View Full Version : Echo three pictures in a row
captainjustin
09-07-2010, 12:43 AM
My name is justin and I'm very new to php.. I understand the basic(very Basics) and I'm trying to create a photo gallery with three pictures on each row. The picture names are in a table called (job_banner_t) and the image file name is in a row called fn..... I posted this in the past and got some pointers but, I just can't seem to get it right... My code that isn't working is listed below, and I would greatly appreciate any help...
<?
include_once "accesscontrol.php";
$sb = "select * from job_banners_t";
$rsb = mysql_query($sb) or die(mysql_error());
if(mysql_num_rows($rsb) > '0')
{
echo "<table align=center width=600><caption align=center><b>Photo Album </b></caption><tr><br><td colspan=2><hr width=100% height=1px color=#000099></td></tr>";
while ($ab = mysql_fetch_assoc($rsb)) {
$myimgs[] = $row['fn'];
{
echo '<table><tr>';
for($x=0;$x<count($myimgs);$x++) {
if ($x%3==0) { echo '</tr>'; }
echo '<td><img src=\"http://$_SERVER[HTTP_HOST]$dir/photo_album/$ab[fn]\" width=\"120\" height=\"100\" /></td>';
}
echo '</tr></table>';
?>
djr33
09-07-2010, 02:16 AM
Try changing this:
if ($x%3==0) { echo '</tr>'; }
to:
if ($x%3==0) { echo '</tr><tr>'; }
captainjustin
09-07-2010, 02:30 AM
I'm not sure whats going on... Changing the if ($x%3==0) { echo '</tr><tr>'; } didn't do anything. It seems to be a syntax error or something. The page is blank and white when I try to see the page.
djr33
09-07-2010, 03:05 AM
It looks like you have several extra { brackets open, but missing } brackets to close those code blocks. Try adding a few (1-3) to figure out which one is the problem.
Unless they're later in the script, in a part you didn't include here, your brackets aren't all in pairs. That could be a problem.
<? // you should use full tags: <?php
include_once "accesscontrol.php";
$sb = "select * from job_banners_t";
$rsb = mysql_query($sb) or die(mysql_error());
if(mysql_num_rows($rsb) > '0')
{ // <-- this one has no closing bracket
echo "<table align=center width=600><caption align=center><b>Photo Album </b></caption><tr><br><td colspan=2><hr width=100% height=1px color=#000099></td></tr>";
while ($ab = mysql_fetch_assoc($rsb)) {
$myimgs[] = $row['fn'];
{ // <-- this one has no closing bracket
echo '<table><tr>';
for($x=0;$x<count($myimgs);$x++) {
if ($x%3==0) { echo '</tr>'; }
echo '<td><img src=\"http://$_SERVER[HTTP_HOST]$dir/photo_album/$ab[fn]\" width=\"120\" height=\"100\" /></td>';
}
echo '</tr></table>';
?>
Something else: All the code here is dependent on getting a result from your database query ( if(mysql_num_rows($rsb) > '0') ). Do you know that there is a result? Add this right after the $rsb = mysql_query($sb) or die(mysql_error()); line:
if(mysql_num_rows($rsb) == 0){ echo 'no results to show'; }
captainjustin
09-07-2010, 05:02 AM
Ok so I got another script to work but it has one small problem.. When it echos the <image tag and the $[row] it adds some weird symbols and % stuff to the image name... Which in return does not display the image properly. The image location should be:
http://oilfield-mariners.com/rabbit_patch/photo_album/(Image Name)
However when I right click on the blank image and copy the image location... This is what I get.
http://oilfield-mariners.com/rabbit_patch/members/%5C%22photo_album/1283828005_anchor.jpg%5C%22
Here is the
<?php
include 'accesscontrol.php';
// Set how wide you want your table
$tblWidth = 4;
// Make your query
$sql = mysql_query("SELECT * FROM job_banners_t");
$i = 1;
echo '<table align=center>';
// Check to see if any results were returned
if(mysql_num_rows($sql) > 0){
echo '<tr>';
// Loop through the results
while($row = mysql_fetch_array($sql)){
echo '<td><img src=\"photo_album/'. $row['fn'] .'\" width=\"120\" height=\"100\" /></td>';
if($i == $tblWidth){
echo '</tr><tr>';
$i = 0;
}
$i++;
}
echo '</tr>';
}else{
echo '<tr><td>No Results Found</td></tr>';
}
echo '</table>';
?>
Any Suggestions?
bluewalrus
09-07-2010, 12:56 PM
Remove the \'s those are to escape the double quotes but you're not using them
so this
echo '<img src=\"photo_album/'. $row['fn'] .'\" width=\"120\" height=\"100\" /></td>';
should be
echo '<img src="photo_album/"'. $row['fn'] .' width="120" height="100" /></td>';
you can also get that kind of stuff if you have spaces in the filename.
katierosy
09-16-2010, 03:21 PM
This example will help.
<?php
mysql_connect('localhost','root','');
mysql_select_db('exp_eng');
$rsb = mysql_query("select name from about");
while($ab = mysql_fetch_assoc($rsb)){
$myname[] = $ab['name'];
}
echo '<table><tr>';
for($x=0;$x<count($myname);$x++){
if($x%3==0){
echo '</tr><tr>';
}
echo '<td>'.$myname[$x].'</td>';
}
echo '</tr></table>';
?>
captainjustin
11-30-2010, 06:19 AM
Ok so I got this script that works fine but I was wondering if there is a way for the thumb nails to load faster... I'm using the fancy box light box picture viewer.. Got any suggestions?
<?
$submit=fn;
$order_type=fn;
if (!$ByPage) $ByPage=8;
if (!$Start) $Start=0;
// Set how wide you want your table
$tblWidth = 4;
// Make your query
$sql = mysql_query("SELECT * FROM photo_album order by date desc limit $Start,$ByPage ");
$i = 1;
echo '<table align=center>';
// Check to see if any results were returned
if(mysql_num_rows($sql) > 0){
echo '<tr>';
// Loop through the results
while($row = mysql_fetch_array($sql)){
echo '<td><a rel="example_group" href="images/'. $row['fn'] .'" title="'. $row['title'] .'"><img src="images/'. $row['fn'] .'" width="120" height="100" /> </a><br><center><a href="delete_pic.php?fn='. $row['fn'] .'" ><img src="icons/delete.gif" width="21" height="16" title="Delete Picture" border="0"/></a> <a href="edit_comments.php?fn='. $row['fn'] .'" ><img src="icons/comments.png" width="16" height="16" title="Edit Comments" border="0"/></a></td>';
if($i == $tblWidth){
echo '</tr><tr>';
$i = 0;
}
$i++;
}
echo '</tr>';
}else{
echo '<tr><td>No Pictures Posted Yet!</td></tr>';
}
echo '</table>';
$cp = "select count(fn) from photo_album";
$rcp = mysql_query($cp) or die (mysql_error());
$ap = mysql_fetch_array($rcp);
$a = $ap[0];
echo "<table width=500 align=center cellspacing=0><tr>";
if ($a <= $ByPage && $Start == '0')
{
}
elseif ($a > $Start + $ByPage && $Start + $ByPage >= $a || $Start == 0 )
{
$nom = $Start + $ByPage;
echo "<td align=right><a class=TNA href=\"admin_album.php?submit=$submit&order_type=$order_type&Start=$nom\">Next Page <img src=\"icons/next.gif\" width=\"16\" height=\"16\" alt=\"Next Page\" border=\"0\"/></a></td>";
}
elseif ( ($Start < $a && $Start > $ByPage) || ($Start + $ByPage >= $a))
{
$nom1 = $Start - $ByPage;
echo "<td align=left><a class=TNA href=\"admin_album.php?submit=$submit&order_type=$order_type&Start=$nom1\"><img src=\"icons/back.gif\" width=\"16\" height=\"16\" alt=\"Next Page\" border=\"0\"/> Back</a></td>";
}
echo "</tr></table>";
exit;
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.