Can someone tell/show me how to use PHP inside PHP.
I’m trying to make the URL of an image change depending on what value is in a MySQL database.
Here’s an example of what I’m trying to do. Bear in mind that $idx already has a value from the URL of the page.
<?php
$query = "SELECT * FROM comment WHERE uname='$idx'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<img src='' name='comm' width='75px' height='60px' id='mainimage' />";
}
?>
How would I make the source value, for the image, come from a different table?
You’d do another SQL query inside the
whileloop. I like how you put it, “Php inside Php”, that’s pretty much what you do.Make sure the variable names for your query and result are different from your original query, because you’re still using the
$resultvariable from the original query each iteration of the loop. So here I’ve prefixed them with “image_”.