Jump to content

Need Help With mySQL Query


jamesbrauman

Recommended Posts

Hello all, how are you going?

I have a table inside my database called 'literatureworks'. This table contains information about lots of different literature works. This table is set out like so:

 

[id]  [name]  [category]  [genre]  [date_submitted] ....

 

I am using PHP and MySQL, and I want to craft a query to return the number of items per genre where the category is equal to the category I specify, as well as the current genre name and category name. I will then loop through the rows retured (hopefully there is one row per genre returned), and echo this to my page. My brain is half-dead this morning, so forgive me, but this is what I have so far:

 

//Query the database and get the result

$result = mysql_query("SELECT * FROM literatureworks, COUNT(name) WHERE category='Fiction' GROUP BY genre");

//Start our loop

while ($ow = mysql_fetch_array($result)) {

$currentcategory = "Fiction";

$currentgenre = $row['genre'];

$totalitemsingenre = $row['COUNT(name)'];

echo "$currentcategory: $currentgenre contains $totalitemsingenre items.";

}

 

I have no idea where to go from here, thankyou for reading.

Link to comment
https://forums.phpfreaks.com/topic/120293-need-help-with-mysql-query/
Share on other sites

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.