PHP Links + images form MySQL DB
I know i was having troubles with this a while ago but as i found a way in a PHP book on how to solve it i thought i will share it.
lets say your db has a column for websites and another for images and you want to make a list that displays all the info in the db including the website as a link and an image. well here is how to do it:
-
// -----------------------------------------------
-
-
for ($i=0; $i<$num_links; $i++)
-
{
-
//part 1
-
$id = $row["id"];
-
$name = $row["name"];
-
$email = $row["email"];
-
$website = $row["website"];
-
$description = $row["brief_description"];
-
$image_dir = $row["image_dir"];
-
-
//part 2
-
print "User Id : $id
-
";
-
print "Name : $name
-
";
-
print "E-mail : $email
-
";
-
";
-
print "brief description : $description
-
";
-
print "image is <img src="$image_dir" alt="" />
-
-
";
-
}
-
?>
As you see in part 1 we got the data from the database. this is all what we need for now.
In Part 2 we print the data out that we stored before as variables. so it will view a block containing id,name,email,website,brief description and an image.
For the link i used:
-
";
what this does is it writes website then makes a link command telling it to hyperlink to the website that we got from the variable.
the same with the image image tag with a variable for the actual image. so it looks like this:
-
";
I hope that helps someone.
Popularity: unranked [?]

