I actually have a few questions here: My end goal is to write a script that will automatically display all the images that i have saved inside my database(If i add new images to my database(image URLs), each time i refresh the page i would like those “new” images to be instantly displayed as well).
-
What is the proper way to save an image URL inside MySQL? Currently i set my input type to VARCHAR; is that okay for image URLs?
-
Also, at the moment i’m working with WAMP server just to test how the site is working; so i put an image inside the www folder(within the same folder as my php script) and inside the database table i simply put the URL as follows: image.png
is this the correct way to enter an image URL inside my database? -
What is the best way to display these images in a sequence? The following code is what i have so far:(the image widths will take up about 70% of the page so the images will not be next to each other; they will be in a column form.)
<?php $db_host="host"; $db_user="user"; $db_pass="pass"; $db_name="name"; $db_table="table"; mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error()); $query = mysql_query("SELECT * FROM tablename"); $result = mysql_query($query); $num = mysql_num_rows($result); for($count = 0; $count < $num; $count++) { //output the rows one by one(the actual images, not the URLs) mysql_fetch_row($result); echo("<br/>"); } ?>I don’t know if i should be using mysql_fetch_row in there..
-
I want my images to have some space in between; i was thinking the best way to accomplish that would be to add a “br” tag at the end of my loop so that every time a new image is displayed, a line break will be added to the end of the page.. Is that the best way to do it?
Thanks a bunch in advance!
To your first question, yes. To your second, also yes, if all your images are stored in the same directory. Mostly it’s a matter of preference though.
Your for loop should look like this:
brtags would probably be a bad idea. Set the images’displayproperty toblockin your CSS file. There are plenty of CSS manuals online.