DrTrans Posted October 16, 2009 Share Posted October 16, 2009 need a simple way to count records in a sql statement basically in my table i have a row called " skey " for everytime that key is entered in the database i wanna know how many times it is thanks Quote Link to comment https://forums.phpfreaks.com/topic/177940-solved-counting-records/ Share on other sites More sharing options...
cags Posted October 16, 2009 Share Posted October 16, 2009 SELECT COUNT(column_name) FROM table_name WHERE column_name='skey' Quote Link to comment https://forums.phpfreaks.com/topic/177940-solved-counting-records/#findComment-938184 Share on other sites More sharing options...
DrTrans Posted October 16, 2009 Author Share Posted October 16, 2009 Heres my code <?php $connect = mysql_connect("localhost","damgears_evil","damgears"); mysql_select_db("damgears_evil"); $queryreg = mysql_query("COUNT (*) FROM titles"); ?> <p align="center">There have been <?php echo"$amountitles"; ?> set with our Titler.</td> Quote Link to comment https://forums.phpfreaks.com/topic/177940-solved-counting-records/#findComment-938199 Share on other sites More sharing options...
DrTrans Posted October 16, 2009 Author Share Posted October 16, 2009 $amountitles isnt set. I need to make $amountitles = ( amount of titles counted) Quote Link to comment https://forums.phpfreaks.com/topic/177940-solved-counting-records/#findComment-938203 Share on other sites More sharing options...
cags Posted October 16, 2009 Share Posted October 16, 2009 a.) I believe COUNT cannot be used like that and you should infact use SELECT COUNT. b.) At no point in your code do you seem to set $amounttitles to any value. mysql_query always returns a resource object even if logically you know it will just be one value. You will need to use $row= mysql_fetch_array($queryreg); and $amounttitles = $row[0]; Quote Link to comment https://forums.phpfreaks.com/topic/177940-solved-counting-records/#findComment-938208 Share on other sites More sharing options...
Psycho Posted October 16, 2009 Share Posted October 16, 2009 From my interpretation of your first post, I think you are saying there will be multiple records with the same 'skey' value and want to know how many times each one appears. If that is the case you will need something a little different: SELECT skey, COUNT(skey) as count FROM titles GROUP BY skey That will return a separate record for each unique value along with the number of times it appears. Quote Link to comment https://forums.phpfreaks.com/topic/177940-solved-counting-records/#findComment-938220 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.