I have a database query that displays pages for various animal species (e.g. MySite/Animals/Tiger). My code looks like this. (I deleted some of the field names to make it a little more readble.)
$Life = mysql_fetch_assoc(mysql_query("SELECT L.Taxon, G.TaxonG, I.MyURL
FROM gz_life L
LEFT JOIN gz_ghosts as G ON G.TaxonG = L.Taxon
WHERE L.Taxon LIKE '$MyURL'"));
$MyName = str_replace('_', ' ', $Life['Taxon']);
$Parent = $Life['Parent'];
$MyFam = $Life['MyFam'];
$MyOrd = $Life['MyOrd'];
$MyCla = $Life['MyCla'];
$Rank = $Life['Rank'];
$Ghost = $Life['Wild_Card'];
$Wild_Card = $Ghost;
I created another database table (gz_images) to help me display images. So I changed my query to this:
$Life = mysql_fetch_assoc(mysql_query("SELECT L.Taxon, G.TaxonG, I.MyURL
FROM gz_life L
LEFT JOIN gz_ghosts as G ON G.TaxonG = L.Taxon
LEFT JOIN gz_images as I ON I.MyURL = L.Taxon
WHERE L.Taxon LIKE '$MyURL'"));
…and I added some more echo values:
$Img = $Life['Img'];
$ImgName = $Life['ImgName'];
$Width = $Life['Width'];
$Height = $Life['Height'];
$Div = $Life['Div'];
$Source = $Life['Source'];
$Permission = $Life['Permission'];
$Caption = $Life['Caption'];
It works to a point; it only displays one image.
Here’s some more code…
switch($Img)
{
case 'Intro1':
$ImgIntro1 = '(Whatever)';
break;
case 'Intro2':
$ImgIntro2 = '(Whatever)';
break;
default:
break;
}
I then echo $ImgIntro1 and $ImgIntro2 on my pages. However, only $ImgIntro1 displays an image.
If I have TWO pictures of a wolf, my DB table would look something like this…
MyURL Img
Wolf Intro1
Wolf Intro2
In other words, there are multiple Wolf rows (field MyURL), but my code is apparently just picking up the first row.
I changed the query from a left join to a right join, but that didn’t work. Then I inserted a WHILE LOOP, as follows…
// IMAGES...
// while ($row = mysql_fetch_array($Life, MYSQL_ASSOC))
while ($row = mysql_fetch_assoc($Life))
{
$Img = $Life['Img'];
$ImgName = $Life['ImgName'];
$Width = $Life['Width'];
$Height = $Life['Height'];
$Div = $Life['Div'];
$Source = $Life['Source'];
$Permission = $Life['Permission'];
$Caption = $Life['Caption'];
}
However, I’m not very familiar with while loops. I tried several variations, but nothing works.
Can anyone tell me what the solution is?
Thanks.