Re: Problems with FOR loop
Posted: Wed Feb 13, 2013 10:08 am
Nope. Still no luck. Here's the new version of the code:
I've echoed the $sibquery string and it definitely displays correctly as $sibling1urn. If I take away the MySQL section and allow the code to loop, I get $sibling1urn to $sibling16urn displayed.
The problem is STILL how to get PHP to ignore the $ sign at the end of the $query line. I've tried using the HTML code for the dollar sign ($) but this doesn't work either.
Three days I've spent playing with this and I'm still no closer.
Just to reiterate, the above code (as clunky as it is) works perfectly without the loop. It displays the data fine (when combined with the CSS of my site).
But throw the FOR loop in to the mix and it all goes wrong.
Please, PLEASE can anybody help?
Kris.
Code: Select all
...
<body>
URN: $mainurn<br/>$forename $middlenames $surname ($yearofbirth)<br/><br/>"; // JUST TO TEST THAT dB IS ACCESSED AND WORKING
for ($i=1;$i<=16;$i++) {
$sibquery = '$sibling' . $i . 'urn'; // THIS ECHOES FINE
$fields = "urn,surname,forename,middlenames,yearofbirth,bloodline";
// EXTRACT DATA AND DISPLAY
$query = "SELECT $fields FROM tree WHERE urn = '$sibquery'";
$result = mysql_query($query)
or die ("Couldn't execute query");
while($row = mysql_fetch_assoc($result)) {
extract($row);
if (strlen($i) < 2) {
$prefix="0";
} else {
$prefix="";
}
if ($bloodline == "AA0000") {
echo " <tt>$prefix$i:</tt><a href='$link$urn' class='bloodline'>$forename $middlenames $surname ($yearofbirth)</a> <br/>";
} elseif ($bloodline != "AA0000") {
echo " <tt>$prefix$i:</tt><a href='$link$urn' class='footer'>$forename $middlenames $surname ($yearofbirth)</a> <br/>";
}
}
}The problem is STILL how to get PHP to ignore the $ sign at the end of the $query line. I've tried using the HTML code for the dollar sign ($) but this doesn't work either.
Three days I've spent playing with this and I'm still no closer.
Just to reiterate, the above code (as clunky as it is) works perfectly without the loop. It displays the data fine (when combined with the CSS of my site).
But throw the FOR loop in to the mix and it all goes wrong.
Please, PLEASE can anybody help?
Kris.