Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Php Links + images form Mysql db

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
Watch
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 coloumn 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:

PHP:
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("db_name");
// -----------------------------------------------

$result = mysql_query("SELECT * FROM table order by 'id'")or die(mysql_error());
$num_links = mysql_num_rows($result);
for ($i=0; $i<$num_links; $i++)
{
//part 1
$row= mysql_fetch_array($result);
$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 <br />";
print "Name : $name <br />";
print "E-mail : $email <br />";
print "Website : <a href=http://$website>$website</a><br />";
print "brief description : $description <br />";
print "image is <img src='$image_dir'> <br /><br />";
}
?>

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 discription and an image.

For the link i used:
PHP:
 print "Website : <a href=http://$website>$website</a><br />";
what this does is it writes website then makes a link command tellink it to hyperlink to the website that we got from the variable.

the same with the image image tag with a variable for the acctual image. so it looks like this:

PHP:
print "image is <img src='$image_dir'> <br /><br />";
I hope that helps someone.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back