sblake161189 Posted June 2, 2011 Share Posted June 2, 2011 Hi All, I think im having one of those days when you want to rip your hair out... My problem is... I want to produce the total number of results in my table that match a particular query... that query in English is... calculate the total number of records where field category = C Category... When im in phpMyadmin and perform a search it finds all the records that have the value of C Category in the category field. If I then choose 'show php code' i get: $sql = "SELECT * FROM `staff` WHERE `category` = \'C Category\' LIMIT 0, 30 "; In my php document, i use... <?php include ('config.php'); $sql="SELECT * FROM `staff` WHERE `category` = \'C Category\' LIMIT 0, 30 "; $result=mysql_query($sql); $num_rows = mysql_num_rows($result); echo $num_rows; ?> But I get a blank page... what am I doing wrong? Cheers Link to comment https://forums.phpfreaks.com/topic/238222-mysql_num_rows-of-sql-query/ Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 try this: $sql="SELECT count(*) as total FROM `staff` WHERE `category` = 'C Category'"; Keep in mind that phpMyAdmin adds LIMIT 0,30 to the end of your queries. hope this helps, Link to comment https://forums.phpfreaks.com/topic/238222-mysql_num_rows-of-sql-query/#findComment-1224183 Share on other sites More sharing options...
Drummin Posted June 2, 2011 Share Posted June 2, 2011 Have you tried this without backticks? <?php include ('config.php'); $sql="SELECT * FROM staff WHERE category = 'C Category' LIMIT 0, 30 "; $result=mysql_query($sql); $num_rows = mysql_num_rows($result); echo $num_rows; ?> Link to comment https://forums.phpfreaks.com/topic/238222-mysql_num_rows-of-sql-query/#findComment-1224184 Share on other sites More sharing options...
sblake161189 Posted June 2, 2011 Author Share Posted June 2, 2011 Webstyles that works mint, thank you very much! Link to comment https://forums.phpfreaks.com/topic/238222-mysql_num_rows-of-sql-query/#findComment-1224185 Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 quite welcome! Link to comment https://forums.phpfreaks.com/topic/238222-mysql_num_rows-of-sql-query/#findComment-1224186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.