Forum Moderators: open
$sql = "SELECT id FROM photos";
$result = mysql_query($sql) OR die("Couldn't select Data.");
$num = mysql_numrows($result);
With that code it seems like a waste to have to select a bunch "id"s just to find out how many rows there are. What if there were 1,000,000 rows? Isn't the code a bit resource intensive?
I want to select a random id (row of data) from the database but first I need to know the total number of rows right?
For example, I need to know that there are 200 rows (ids) so that I limit my random number to 200 or below correct?
So I'm curious about if there are any other ways to know how many rows there are.
===
Also, does anyone know how to select the last 5 rows of a database without knowing how many total rows there are? Like if I wanted to display the last 5 rows of data that were added.
Many thanks.