i have database list for users and user's coupons and i want to add +1 ticket per coupon if bigger than two between numbers.
For example:
100 between 200 = 1 ticket
200 between 300 = 2 ticket
300 between 400 = 3 ticket
.......
.......
1200 between 1300 = 12 ticket
i put photo for example:
My Code is :
$q=$db->query("SELECT DISTINCT client_id FROM kuponlar ORDER BY client_id LIMIT 20");
foreach($q as $cat){
echo '<li id="'.$cat['client_id'].'" class="files">';
echo 'User ID: <a href="'.$cat['client_id'].'">'.$cat['client_id'].'</a>';
echo '<ul class="sub-menu">';
$linkq=$db->query("SELECT * FROM kuponlar WHERE client_id='" . $cat['client_id'] . "'");
foreach($linkq as $link){
echo '<li>Coupon ID: <a href="#">'.$link['kuponid'].'</a> - Coupon Price: '.$link['yatirimi'].' ₺ / Won Ticket: '.substr($link['yatirimi'], 0, 1).' </li>';
}
echo '</ul></li>';
}
You can do this using floor()
:
http://php.net/manual/en/function.floor.php
floor — Round fractions down
So this should do the trick: floor($link['yatirimi'] / 100)
Use that in place of your substr
.
you can user this: $wonTicketsCount = round(($link['yatirimi'] / 100 ) - 0.5);
instead substr($link['yatirimi'], 0, 1)
.
Refering to your comments if you only use hundreds steps :
Modify this line :
substr($link['yatirimi'], 0, 1)
This line will always take the first number.
By : this one This will take all numbers excepts the two lasts.
substr($link['yatirimi'],0,-2);
By keeping the substr, it will not work for number between 0-100, It's better to use @Qirel's Anwser.
As discussed in the comments;
- So if the number is 12 000, you want 120 as a result? Basically divide by 100? – Qirel
- Yes @Qirel this is perfect comment. i mean like this. (...) – Ismail Altunören
So put simply, you want to divide the number by 100. You must then floor it, to get a full integer and get rid of any decimal points.
floor($link['yatirimi']/100);
You would replace that with your substr()
, making the full line
echo '<li>Coupon ID: <a href="#">'.$link['kuponid'].'</a> - Coupon Price: '.$link['yatirimi'].' ₺ / Won Ticket: '.floor($link['yatirimi']/100).' </li>';