FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to show a lot of pictures with php?





ulruc
Some of my friends told to me that when you have a lot of pictures on a web site, you can create yourself a database with them so you don't have to code them all in HTML or XHTML.

If that is really true, can someone tell me how can I do that. Il have actually more than 250 pictures and I'm tired to code them one by one each time I need to change the setup of that section.

Who can help me?
Rhysige
its very possible, lets say for a really simple method you have a database with a table called `images` and in this table are the fields `id` (if you want to be able to select specific ones later easily) and `path`.
Now in the `path` field are all the image paths. A php script to just display all of these would be something like this.

Code:

<?PHP

$res = mysql_query("SELECT * FROM `images`");

while($row = mysql_fetch_object($res)){
        echo '<img src="' . $row->path . '" /><br />';
}
?>


But if you want more complex codes learn PHP :p or find a gallery script
dingin
Why don't give a try with Coppermine? It's more simple to host many pictures in the web
ccarter24
Did you mean create a database that stores the images files, or just the file information. I know oracle can store binary files up to 4 GB. It's pretty cool. But I don't know about MySQL.
PublicKiosk
mysql can store the text. it can't store the image. so once the image is on your site, its path should be added to the mysql database.


so if 'image1.png' is uploaded to 'http://www.example.com/images/image1.png'
then the php engine should add the image name 'image1.png' to the database as a TEXT format. then, when you fetch the rows, the code would resemble:

Code:
<?PHP

$res = mysql_query("SELECT * FROM `images`");

while($row = mysql_fetch_object($res)){
        echo '<img src="images/' . $row->path . '" /><br />';
}
?>
Related topics
Guess the movie (Game)
751 Useful Windows XP Files
Site Nav Suggestions...
my website
PHP Counter?
30 gigabytes Email
Calendar with PHP
installing apache,mysql and php on windows
My page can be viewed in IE but not Firefox!
PHP with Frihost [need help]
March to be the Month of PHP Bugs
Best PHP FRAMEWORK
PHP vs ASP
Travel Tips for an Excursion... to America?
Premonitory dream
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.