Jump to content

while loop


astralaaron
 Share

Recommended Posts

can someone tell me how to write this out to loop through images?

<?php $name = $_GET['name']; //holds the gallery namemysql_connect("localhost","root","astralaaron")or die("connection error");mysql_select_db("galleries")or die("database 1 error");$sql = "SELECT * FROM $name ORDER BY id DESC";$result = mysql_query($sql)or die("no sql result");?><html><body><table width="100%" height="100%" border="1"><tr><td><a href="main.php">click</a></td></tr><?php while ($rep = mysql_fetch_array($result)) { ?><tr><td><?php echo "<IMG SRC=\"container/" . $name . $rep['name']; .".jpg"> ?></td>    //theres only 2 fields in the galleries table right now, just `id` and `name`</tr><?php } ?></table</body></html>

I don't know how to use the variables in the echo ...

Link to comment
Share on other sites

Well, you can put it like this:- Strings are marked in green- I added ".jpg" in red<?php echo "<IMG SRC=\"container/" . $name . $rep['name'] . ".jpg\">"; ?>The output would look something like this:<IMG SRC="container/filename.jpg">

Link to comment
Share on other sites

Actually, that could be quite complicated...There is a simple solution, but with drawbacks: it will take just as long to load as a big image.Just echo:<?php echo "<a href=\"container/" . $name . $rep['name'] . ".jpg\"><IMG SRC=\"container/" . $name . $rep['name'] . ".jpg\" width="80"></a>"; ?>The complicated solution would be this:You create a file called image.php and use the PHP GD library to make the file an image that loads other images dynamically with a $_GET variable and shrinks them. (I could do this, but it would take a while to make the script for the file)After that you make the echo command like this:<?php echo "<a href=\"container/" . $name . $rep['name'] . ".jpg\"><IMG SRC=\"image.php?i=" . $name . $rep['name'] . "\"></a>"; ?>

Link to comment
Share on other sites

The photo gallery that I posted for you in the other thread does image resizing. Check the add_image function inside the functions.php file to see an example. It takes the original image, resizes it if it's too big, creates a thumbnail of a specific size, and saves both of them in the database. The view_img script gets the images from the database and sends them to the browser.

Link to comment
Share on other sites

The photo gallery that I posted for you in the other thread does image resizing. Check the add_image function inside the functions.php file to see an example. It takes the original image, resizes it if it's too big, creates a thumbnail of a specific size, and saves both of them in the database. The view_img script gets the images from the database and sends them to the browser.
yeah i saw the option to resize, it is awsome the way you did that gallery, I am sure it is much better than the this way I am trying
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...