Jump to content

Recommended Posts

If I have a query:

$querySongs = "SELECT COUNT(songID)

FROM vote

WHERE songID = '$songID'";

$resultSongs = mysql_query($querySongs) or die (mysql_error());

$rowSongs = mysql_fetch_assoc($resultSongs);

 

How do I grab the COUNT(songID)?

 

like this:

$count = rowSongs[COUNT(songID)];

??

 

thanks....

 

by the way, whoevr wrote that tutorial on UNION JOINS thank you so much....awesome tutorial.  I learned so much about the proper way to structure queries and logically break down what they are doing.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/146167-solved-help-grabbing-count/
Share on other sites

$querySongs = "SELECT COUNT(songID) as SongCount
            FROM vote
            WHERE songID = '$songID'";
$resultSongs = mysql_query($querySongs) or die (mysql_error());
$rowSongs = mysql_fetch_assoc($resultSongs);
echo $rowSongs['SongCount'];

 

Should do it.

 

Using the "AS" keyword allows you to create an alias of the actual field (essentially renames it when it is fetched).

 

EDIT:

To not use the "as" this would also work. And actually I prefer this way for these type of queries:

$querySongs = "SELECT COUNT(songID)
            FROM vote
            WHERE songID = '$songID'";
$resultSongs = mysql_query($querySongs) or die (mysql_error());
$rowSongs = mysql_result($resultSongs, 0);
echo $rowSongs;

 

As you just pull that first column out :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.