Jump to content

while loop


astralaaron

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

#21 <?php while ($rep = mysql_fetch_array($result)) { ?>#22 <tr>#23 <td><?php echo "<a href=\"container/" . $name . "/" . $rep['name'] . ".jpg\"><IMG SRC=\"container/" . $name . $rep['name'] . ".jpg\" width=\"80\"></a>"; ?></td>#24 </tr>#25 <?php } ?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...