Forum Moderators: coopster

Message Too Old, No Replies

Selecting two tables to label ID number

Labels for polls are stored separately from ID number

         

s9901470

12:10 am on Nov 30, 2005 (gmt 0)

10+ Year Member



Hi

I have a polling system storing votes for 50 polls.
I want to display the results to visitors, but I have stored them according to ID number in the results table. Their labels are stored in a different table.

I want to print:

Label (from polls)
Average rating (from polldata)
Total ratings (from polldata)

The two tables are linked by ID only.

The code below just prints the ID number and the average and total votes, and I don't know how to link up the labels from the polls table.

Any suggestions?

$query = "SELECT SUM(rating) AS total, AVG(rating) AS mean, id AS label
FROM polldata GROUP BY id";
$i = 0;
$ask = mysql_query($query) or die("Select Failed!");
while($row = mysql_fetch_array($ask))
{
echo "<p><strong>" . $row['label']. "</strong> ".$row['mean']." (".$row['total'].")<BR>";
}

wsmeyer

5:18 am on Nov 30, 2005 (gmt 0)

10+ Year Member



You might want to post in the database forum as what you're having trouble with is a MySQL query.

You can also try searching the MySQL manual for "inner join" I know it's what you want to do but I don't know enough about it to tell you exactly how to do it.

William.