FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

list number of rows in a table

 


alalex
how can i get into a variable the number of rows in a table? Sad
hexkid
alalex wrote:
how can i get into a variable the number of rows in a table?


Well ... if the table has 42 rows just do
Code:
$a_variable = 42;




Just kidding Smile



try
Code:
$sql = 'select count(*) from a_table';
$res = mysql_query($sql) or die('query error on line ' . __LINE__ . ': ' . mysql_error());
$a_variable = mysql_result($res, 0, 0);
mysql_free_result($res);
alalex
Shocked thanks, you really know a lot about php!
thanks Very Happy
jeremyw
Depending on the version of PHP or MySQL support you have, this might also work:
Code:
$say = 'select * from table';
$answer = mysql_query($say) or die('Query failed: '.mysql_error());
$rows = mysql_numrows($answer);

This is the way that works for my setup, it may be different depending on how you have PHP and your MySQL extensions set up.
hexkid
jeremyw wrote:
...

http://www.frihost.com/forums/vp-508437.html#508437
mathiaus
Yeah Mr. Green . I've been wanting to use this image for ages ...



-close-
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.