Jump to content

Getting data from a table based on the results from another?


hatrickpatrick

Recommended Posts

This is the second part of my problems with a top ten list:

I'm making a site for guitar effects. I'm trying to make a list of the top ten effects pedals, based on how many effects settings (patches) people have submitted for each pedal. There are two tables, pedals and patches:

I want it to select patches and find out which "pedal_id" is most common, then select that pedal ID from pedals, echo some tuff, then do the query again, except search for the SECOND most popular value, echo it, then the third, echo it, etc etc etc

 

Anyone know if this is possible?

Link to comment
Share on other sites

Probably an easier way but this will work
<?php
$id = "The Field you are counting";
$q = "Select ".$id." From `Table` Order by ID Desc";
$r = mysql_query($q) or die(mysql_error());
$temp  = "";
$counts = array();
while($row = mysql_fetch_array($r)){
if($row[$id] != $temp){$counts[$row[$id]]++;}
$temp = $row[$id];
}
print_r($counts);
?>

see what the $counts has for you.

Link to comment
Share on other sites

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.