Sorry folks but still no joy. I don't think I quite explained myself fully last time.
I run a genealogy website. It uses PHP and MySQL. My database consists of a single entry for each member of our family, all with a Unique Reference Number (URN). Siblings are contained in columns in my database entitled sibling1urn, sibling2urn etc. all the way through to sibling 16urn.
At the point at which I need the following code to work, the data for the "target" individual has already been extracted and echo'd. What I need my site to do now is (using a FOR loop), extract further data from MySQL from strings already extracted.
So I need the loop to download $fields where urn = '$sibling1urn' etc. $sibling1urn is a string already extracted from the database.
I guess what I'm really stuck with is the structure of my SELECT statement. What I need to do is concatenate somehow. When I extract this data MANUALLY, it works fine. It's only when I add the $i in to the equation that things stop working. No errors, just no data returned.
MANUALLY my script looks like this:
Code: Select all
$query = "SELECT $fields FROM tree WHERE urn='$sibling1urn'";
$result = mysql_query($query)
or die ("Couldn't execute query");
while($row = mysql_fetch_assoc($result))
{
extract($row);...
And it works. But having this block repeated SIXTEEN times for each of the siblings is nonsensical!
MY FOR LOOP (WHICH DOESN'T WORK) looks like this:
Code: Select all
for ($i=1;$i<=16;$i++)
{
// EXTRACT DATA AND DISPLAY
$sibsearch = "$sibling{$i}urn";
$query = "SELECT $fields FROM tree WHERE urn='$sibsearch'";
$result = mysql_query($query)
or die ("Couldn't execute query");
while($row = mysql_fetch_assoc($result))
{
extract($row);...
Any ideas as to what I'm doing so wrong in the WHERE part of this code? I've tried \"$sibsearch{$i}urn\", I've tried '$sibsearch{$i}urn', I've tried apostrophes, full stops and still my code resolutely refuses to work....
Thanks in advance...