Forum Moderators: coopster
$sql = "select * from reunion_photos";
$result = mysql_query($sql);
$tdcount = 1;
$numtd = 3; // number of cells per row
while($row = mysql_fetch_array($result)) {
if ($tdcount == 1)
echo "<tr>";
echo "<td><img src=\"$image\" width=\"$width\" height=\"$height\">
</td>"; // display as you like
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1; }
else { $tdcount++; } } // time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td></td>"; $tdcount++; }
echo "</tr>"; }
What exactly do you return from db?
Check it out:
while($row = mysql_fetch_array($result)) {
...
echo "Image: $image Width: $width Height: $height<br>\n";
echo "Direct DB Image: ".$row['image']."<br>\n";
}
And see what happens.
Regards
Michal
$sql = "select * from reunion_photos";
$result = mysql_query($sql);
$countImages= count("$image");
echo "<table><tr>";
for($x=1; $x<=$countImages; $x++) {
echo "<td><img src=\"$image\" width=\"$width\" height=\"$height\">
</td>"; // display as you like
if($x % 3 == 0) {
echo "</tr><tr>";
}
echo "</tr></table>"; }
This script will print each picture only once but it just lines them up vertically instead of the 3 pictures per row. Any suggestions here?
$sql = "select * from reunion_photos";
$result = mysql_query($sql);
echo "<table>";
$counter = 1;
while($row = mysql_fetch_array($result)) {
if(($counter % 3) == 0 ¦¦ $counter == 1) {
echo '<tr>';
}
echo "<td><img src='".$row['image']."' width='".$row['width']."' height='".$row['height']."'></td>";
if(($counter % 3) == 0) {
echo '</tr>';
}
counter++;
}
echo "</table>";
...I think that should do the trick, but I'm tired and cannot think straight!
Good luck
if($x % 3 == 0) {
First is done comparison - and so you get:
if($x % false) {
if($x % 0) {- simple type resolution
if(0) {- omits the tr ending
Correction is:
if(($x % 3) == 0) {
Eelixduppy, sometimes it's better to understand the mistake, than writing the correct, totally different version :)
Regards
Michal
PS. 5:56 am on Nov 13, 2006 is not a time to think ;)
<?php
if ((is_dir("/reunion_photos/$id")) ¦¦ (file_exists("/reunion_photos/$id"))) {
$dirname = "/reunion_photos/$id";
$dh = opendir($dirname) or die("<i>There was an error</i>");
while (false!== ($file = readdir($dh))) {
if ($file!= "." && $file!= "..") {
$image = "$dirname/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$height = 150;
$percent = ($size[1] / $height);
$width = ($size[0] / $percent);
}
else if ($width > 150)
{
$width = 150;
$percent = ($size[0] / $width);
$height = ($size[1] / $percent);
}
$sql = "select * from reunion_photos";
$result = mysql_query($sql);
$countImages= count("$image");
echo "<table width=\"100%\"><tr>";
for($x=1; $x<="$countImages"; $x++) {
echo "<td align=\"center\"><img src=\"$image\" width=\"$width\" height=\"$height\"> </td>";
if(($x % 3) == 0) {
echo "</tr><tr>";
}
}
}
}
echo "</tr></table>";
closedir($dh);
?>
I tried changing the table tags around but can't seem to get that to work either.
1. What is sql doing there? Nothing
2. While looping through files you count one file count($image) = 1 - it's string, not an array
3. Open dir doesn't work on a single file, so file exists you can disregard
Try this out:
if (is_dir("/reunion_photos/$id") {$dirname = "/reunion_photos/$id";
$count = 1;echo "<table width=\"100%\"><tr>";
$dh = opendir($dirname) or die("<i>There was an error</i>");
while (false!== ($file = readdir($dh))) {
if ($file == "." ¦¦ $file == "..") continue;$image = "$dirname/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$width = $width * 150 / $height; //php can do math, it's not assembler
$height = 150;
}if ($width > 150)
{
$height = ($height * 150 / $width);
$width = 150; //this way it shouldn't be bigger in any direction than 150px
}echo "<td align=\"center\"><img src=\"$image\" width=\"$width\" height=\"$height\"> </td>";
if(($count % 3) == 0) echo "</tr><tr>";
$count++;
}//end whileecho "</tr></table>";
closedir($dh);
Isn't that easier?
Michal
PS. I hope I didn't make any mistakes - I didn't check this code
<?php
if (is_dir("/reunion_photos/$id")) {
$dirname = "/reunion_photos/$id";
$count = 1;
echo "<table width=\"100%\"><tr>";
$dh = opendir($dirname) or die("<i>There was an error</i>");
while (false!== ($file = readdir($dh))) {
if ($file == "." ¦¦ $file == "..") continue;
$image = "$dirname/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$width = $width * 150 / $height; //php can do math, it's not assembler
$height = 150;
}
if ($width > 150)
{
$height = ($height * 150 / $width);
$width = 150; //this way it shouldn't be bigger in any direction than 150px
}
echo "<td align=\"center\"><img src=\"$image\" width=\"$width\" height=\"$height\"> </td>";
if(($count % 3) == 0) echo "</tr><tr>";
$count++;
}//end while
echo "</tr></table>";
closedir($dh);
}
?>
<?php
$sql = "select * from reunion_photos WHERE id LIKE '%".$id."%'";
$result = mysql_query($sql,$db);
while ($newArray = mysql_fetch_array($result)) {
$id = $newArray['id'];
$file_comment = $newArray['file_comment'];
$firstname = $newArray['firstname'];
$lastname = $newArray['lastname'];
$maidenname = $newArray['maidenname'];
}
if (is_dir("/reunion_photos/$id")) {
$dirname = "/reunion_photos/$id";
$count = 1;
echo "<table width=\"100%\"><tr>";
echo "<td colspan=\"3\" align=\"center\"><h3>$firstname $lastname $maidenname's Reunion Photo Gallery</h3>
<i>Click on a picture to see it enlarged</i><br><br></td></tr><tr>";
$dh = opendir($dirname) or die("<i>There was an error</i>");
while (false!== ($file = readdir($dh))) {
if ($file == "." ¦¦ $file == "..") continue;
$image = "$dirname/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$width = ($width * 150 / $height);
$height = 150;
}
if ($width > 150)
{
$height = ($height * 150 / $width);
$width = 150;
}
echo "<td align=\"center\"><a href=\"http://www.sbhs76.com/$image\" target=\"_blank\">
<img src=\"$image\" width=\"$width\" height=\"$height\" border=\"0\"></a>
<br>$file_comment<br><br></td>";
if(($count % 3) == 0) echo "</tr><tr>";
$count++;
}//end while
echo "</tr></table>";
}
?>
You need to change few things:
add a column `file` to combine files with comments. It has to contain exact names of files that are in the directory.
You could also add author of the comment if you wish
<?php
$sql = "select * from reunion_photos WHERE id LIKE '%".$id."%'";
$result = mysql_query($sql,$db);while ($newArray = mysql_fetch_array($result)) {
$file = $newArray['file'];
$file_comment[$file][] = $newArray['file_comment']; //this way you can have more comments to one file
$comment_author[$file][] = $newArray['coment_author'];
$firstname = $newArray['firstname'];
$lastname = $newArray['lastname'];
$maidenname = $newArray['maidenname'];}
if (is_dir("/reunion_photos/$id")) {
$dirname = "/reunion_photos/$id";
$count = 1;echo "<table width=\"100%\"><tr>";
echo "<td colspan=\"3\" align=\"center\"><h3>$firstname $lastname $maidenname's Reunion Photo Gallery</h3>
<i>Click on a picture to see it enlarged</i><br><br></td></tr><tr>";$dh = opendir($dirname) or die("<i>There was an error</i>");
while (false!== ($file = readdir($dh))) {
if ($file == "." ¦¦ $file == "..") continue;$image = "$dirname/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$width = ($width * 150 / $height);
$height = 150;
}if ($width > 150)
{
$height = ($height * 150 / $width);
$width = 150;
}echo "<td align=\"center\"><a href=\"http://www.sbhs76.com/$image\" target=\"_blank\">
<img src=\"$image\" width=\"$width\" height=\"$height\" border=\"0\"></a>
<br>";
foreach($file_comment[$file] as $key => $comment)
{
echo "$comment<br /><b>". $comment_author[$file][$key]."</b><br><br>";
}
echo "</td>";if(($count % 3) == 0) echo "</tr><tr>";
$count++;
}//end while
echo "</tr></table>";}
?>
I hope it helps you.
Michal
<?php
$sql = "select * from reunion_photos WHERE id LIKE '%".$id."%'";
$result = mysql_query($sql,$db);
echo "<tr>";
while ($newArray = mysql_fetch_array($result)) {
$file= $newArray[file];
$file_comment = $newArray['file_comment'];
$count = 1;
$image = "reunion_photos/$id/$file";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$width = ($width * 150 / $height);
$height = 150;
}
if ($width > 150)
{
$height = ($height * 150 / $width);
$width = 150;
}
echo "<td align=\"center\"><a href=\"$image\" target=\"_blank\">
<img src=\"$image\" width=\"$width\" height=\"$height\" border=\"0\"></a>
<br>$file_comment<br><br></td>";
if(($count % 3) == 0) echo "</tr><tr>";
$count++;
}//end while
echo "</tr></table>";
?>
.......code....blah...blah
[b]if(($count % 3) == 0 ¦¦ $count == 1) {
echo '<tr>';
}[/b]
echo "<td align=\"center\"><a href=\"$image\" target=\"_blank\">
<img src=\"$image\" width=\"$width\" height=\"$height\" border=\"0\"></a>
<br>$file_comment<br><br></td>";
[b]
if(($count % 3) == 0) {
echo "</tr>";
}[/b]
$count++;
}//end while ......code blah blah....
That should do the trick :)
$columns = 4; //how many columns we wantecho "<table>\n";
$sql = "select * from reunion_photos";
$result = mysql_query($sql);for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
if (($i % $columns) == 0) {
echo " <tr>\n";
}echo "<td><img src=\"" . $row['image'] . "\" width=\"" . $row['width'] . "\" height=\"" . $row['height'] . "\">
</td>\n";if (($i % $columns) == ($columns - 1)) {
echo " </tr>\n";
}
}