Jump to content

[SOLVED] Counting records


DrTrans

Recommended Posts

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>

 

 

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];

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.