note 83647 added to function.mysql-num-rows
| From: | TomFejfar at osu1 dot php dot net | Date: | Thu, 05 Jun 2008 20:56:07 +0000 |
| Subject: | note 83647 added to function.mysql-num-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140157@lists.php.net to get a copy of this message | ||
Improvement to chrisdberry82 at gmail dot com's code:
<?php
$sql = "
SELECT SQL_CALC_FOUND_ROWS
'0', z.id
FROM
zoom AS z
LIMIT
0,6
UNION
SELECT
'1', FOUND_ROWS()
ORDER BY
0 DESC , RAND()";
?>
You can see, that you can even ORDER the final result anyway you like ;)
Then you can fetch the result like this:
<?php
$res = mysql_query($sql);
$count = mysql_fetch_assoc($res);
while($row = mysql_fetch_assoc($res)){
unset($row["0"]); //get rid of the "sorting col"
print_r($row); //or whatever ;)
}
echo $count["id"]; // the total number of rows
?>
And you got rid of the lousy IFs ;)
----
Server IP: 147.32.160.17
Probable Submitter: 90.176.129.9
----
Manual Page -- http://www.php.net/manual/en/function.mysql-num-rows.php
Edit -- https://master.php.net/note/edit/83647
Del: integrated -- https://master.php.net/note/delete/83647/integrated
Del: useless -- https://master.php.net/note/delete/83647/useless
Del: bad code -- https://master.php.net/note/delete/83647/bad+code
Del: spam -- https://master.php.net/note/delete/83647/spam
Del: non-english -- https://master.php.net/note/delete/83647/non-english
Del: in docs -- https://master.php.net/note/delete/83647/in+docs
Del: other reasons-- https://master.php.net/note/delete/83647
Reject -- https://master.php.net/note/reject/83647
Search -- https://master.php.net/manage/user-notes.php