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 Quote Link to comment 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, Quote Link to comment 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; ?> Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 quite welcome! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.