FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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-
Related topics
Best Blogging software
HTML tables with irregular rows and/or columns
Track Visitors, how can i best track visitors on my site
Need Expert help in php-mysql
PHP Help entering values from a text form into a table
Calculating number of rows
Simple php & mysql script
Table less webpage
Efficient search transfer list in Game
Finding out what motherboard you have?
666
Latex Custom Auto List
Table Help / Javascript dopdown menu
[PHP] Some beginner questions
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-2011 Frihost, forums powered by phpBB.