UK Webmaster Talk - Online Marketing - SEO


 

Php Links + images form Mysql db.

This is a discussion on Php Links + images form Mysql db. within the Programming Articles forums, part of the Webmaster Articles/Tutorials category; I know i was having troubles with this a while ago but as i found a way in a php ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Webmaster Articles > Webmaster Articles/Tutorials > Programming Articles

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 26-04-2005, 18:45   #1 (permalink)
WMT Addict
 
Join Date: Apr 2005
Location: Brighton,UK
Posts: 162
iTrader: 0 / 0%
asgsoft is on a distinguished road
Default 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 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 Code:

<?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
$rowmysql_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 Code:
 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 Code:
print "image is <img src='$image_dir'> <br /><br />"


I hope that helps someone.
asgsoft is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
form, images, links, mysql, php

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
How would I make my images links? ShaunBurden Php and MySQL 1 12-03-2007 15:48
Form to Mail HostYorkshire Php and MySQL 0 08-01-2007 19:20
Form help JsPLACEwebby Programming / Scripting / Coding 2 05-12-2005 11:25
Clickable Images and links as smilies asgsoft Programming Articles 0 01-06-2005 23:42
Contact Us Form? Departed Programming Articles 0 22-04-2005 00:31


All times are GMT +1. The time now is 16:41.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41