Passing variable from MySql


This script broke with php7 having to do with global variables. The gist is: if there is an ID number, query and give the details. If there is no ID number, query and print the appropriate list. My script prints the list, and produces the correct URL, but never runs the top half of the script.

How does one get the variable from the PHP_SELF at the bottom to query at the top of the page .


if ($idr) 
		$photo_result = mysqli_query($db,"SELECT id, photos FROM TABLE WHERE id=$idr");
		$result = mysqli_query($db,"
			if($r = mysqli_fetch_array($result))
					printf("<a href=\"%s?idr=%s\">%s</a><br>\n", $PHP_SELF, $r["ID"],  $r["ID"]);
				while ($r = mysqli_fetch_array($result));	
				echo "Sorry, no dice! ";

Thanks in advance for any suggestions.


Looks like you have an issue with quotes.

As a general rule however, programming works in the following series,



Thanks Astonecipher,
That makes sense, so I how to I get the input into the top? Drop the if / else and pass the variable down the script?

The script generates a url like:
Which used to produce all the details on 1.

Thanks again


Where is that variable? I don’t see it being set anywhere in the posted code.


HI AStoneCipher,
Thanks again. After sleeping on it, I figured it out:


That pulled the ID from the URL and processed it through the top part of the script.

Thanks for trying.