gavenf Posted June 21, 2007 Share Posted June 21, 2007 I want to show the numebr of rows listed in a specific table. The number needs to be visable each time the page loads automatically. The table is called registered The db is called circusart Thanks Link to comment https://forums.phpfreaks.com/topic/56631-solved-msql-count-function-in-a-php-form/ Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 SELECT COUNT(*) AS totalrows FROM registered; Link to comment https://forums.phpfreaks.com/topic/56631-solved-msql-count-function-in-a-php-form/#findComment-279648 Share on other sites More sharing options...
cooldude832 Posted June 21, 2007 Share Posted June 21, 2007 for better optimization don't use star, but a boolean based table variable or ID Link to comment https://forums.phpfreaks.com/topic/56631-solved-msql-count-function-in-a-php-form/#findComment-279654 Share on other sites More sharing options...
teng84 Posted June 21, 2007 Share Posted June 21, 2007 ya use the primary key ASTIG!!! Link to comment https://forums.phpfreaks.com/topic/56631-solved-msql-count-function-in-a-php-form/#findComment-279656 Share on other sites More sharing options...
gavenf Posted June 22, 2007 Author Share Posted June 22, 2007 ya use the primary key ASTIG!!! You say to use a primary key so should it read SELECT COUNT(id) AS totalrows FROM registered; Also do I jsut put his straight into my php page where I want it to appear? Does it work the same for html pages? Do I need to connect tot he db at the very top of the php page first or can it be done in the same spot? Link to comment https://forums.phpfreaks.com/topic/56631-solved-msql-count-function-in-a-php-form/#findComment-279669 Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 you still have to connect from db mysql_connect('your host','userhere','pword here if any'); mysql_seect_db('your db name'); $result=mysql_query('SELECT COUNT(id) AS totalrows FROM registered'); $row=mysql_fetch_assoc($result); echo $row[totalrows];//display the num rows or you can have this echo mysql_num_rows($result);//display num rows Link to comment https://forums.phpfreaks.com/topic/56631-solved-msql-count-function-in-a-php-form/#findComment-279672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.