PDA

View Full Version : Linking tables?


Squintz
12-18-2002, 09:03 PM
I have a table which stores user information...

User:
User_ID
Name


and i have a table the stores Contest Results

Contest_Results:
User_ID
Contest_ID
Votes

i have done this query


SELECT * FROM Contest_Results WHERE Contest_ID = $Contest_ID ORDER BY $Votes Asc


Now i want to list all the users Names Who have entered the contest which i just queryed... How do i do this?

Just for kicks i will add the code i have


<?
$sql = "SELECT * FROM Contest_Results WHERE Contest_ID = $Contest_ID ORDER BY $Votes Asc";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_object($result)){
echo"<tr>"
echo"<td width="100%" height="29">";
echo"<table border="1" width="100%">";
echo"<tr>";
echo"<td width="80%" bgcolor="#1003BD">Author's Name</td>";
echo"<td width="20%" bgcolor="#1003BD">Votes</td>";
echo"</tr>";
echo"</table>";
echo"</td>";
echo"</tr>";
<tr>
}
?>

krycek
12-18-2002, 09:07 PM
This thread belongs in the MySQL forum really :)

If you look there, you will see that the first two threads contain a lot of detailed, useful info that will help you.

Here's one to get you started:

http://www.codingforums.com/showthread.php?s=&threadid=11612

Good luck! :thumbsup:

::] krycek [::

Spookster
12-18-2002, 09:43 PM
Originally posted by krycek
This thread belongs in the MySQL forum really :)



Somebody obviously didn't read the thread entitled "Post questions involving MySQL/SQL in the MySQL forum".

Yes this belongs in the MySQL forum.

Kiwi
12-19-2002, 10:57 AM
To keep things nice and clean, you would use something like:
SELECT Contest_Results.Votes, Users.Name
FROM Contest_Results AS c, Users AS u
WHERE c.Contest_ID = $Contest_ID
AND c.UserID = u.UserID
ORDER BY Votes Asc;

Squintz
12-20-2002, 04:01 AM
thanx for the straight forward answer...