Click to See Complete Forum and Search --> : SQL query


Static42
05-17-2008, 11:14 AM
Hello,
I'm currently converting a lot of my website into PHP/SQL. Right now I'm adding a bunch of the data into a database, but I'm having trouble with how I should pull the data and display it on the page.

I have a table that has TV show episodes data. In one column is the number and the other column has the name. In another table I have a column that has an ID and the other is a number. That number in the second column will relate to the number in the TV show episodes. Here's a diagram that shows what I'm talking about:

http://img.photobucket.com/albums/v91/SableyeRULES/diagram.png

So what should be displayed on the page are the titles: Fox, Bird, and Dog if the ID in the URL is 1 (?id=1), and Cat, Ferret, and Horse if the ID is 2. My question is how would I do this? I assume it would be something like:

mysql_query("SELECT episodes.number, episodes.name, info.number FROM episodes, info");

I'm stuck after that.

chazzy
05-17-2008, 11:34 AM
SELECT e.number, e.name, i.number FROM episodes e, info i
where e.# = i.# and i.ID = 1


obviously you'd replace the 1 in there with the value.

Marcin
05-17-2008, 12:35 PM
could you describe why you use # as an id indetificator ?
if you use tables with fileds named like below:

episodes:
id: 1, 2, 3, 4, 5, 6
names: Fox, Bird, Dog, Cat, Ferret, Horse

info:
id: 1, 2, 3, 4, 5, 6
val: 1, 1, 1, 2, 2, 2

you can use this query:

$id = $_GET["id"];
....
$result = mysql_query("select episodes.names from episodes, info where info.id = episodes.id AND info.val = $id");
....


---------------------------
simpletags.org (http://simpletags.org)