Re: sql query and some math
| From: | Sven | Date: | Wed, 17 Dec 2003 15:56:51 +0000 |
| Subject: | Re: sql query and some math | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-172886@lists.php.net to get a copy of this message | ||
Patrik Fomin schrieb:
...
q2) i got like 100 matches from a database into a $num variable, then i want to devide that by 3 aslong as it can be done, eg: while ($num != 0) { ïf ($num / 3 = true){ some code to display some fields from a database $num = $num - 3; } else { some other code to display $num = 0; } } basicly i want the if statement to check if its more then 3 posts left to print out, if not its gonna print out the remaining last 1 - 2 post in a diffrent way (for the looks)hi patrik, for your second question maybe 'modulus' helps you. <?php $mod = $num % 3; ?> gives you your remaining results (0, 1 or 2) depending on division by 3. another possibility could be the use of 'limit' in your sql-select-statement. hth SVEN