Welcome to WebmasterWorld Guest from 54.157.239.93

Forum Moderators: open

Message Too Old, No Replies

Small php sql help

php,sql

     
8:18 am on Mar 15, 2010 (gmt 0)

New User

5+ Year Member

joined:Mar 10, 2010
posts: 5
votes: 0


Hi

I have a small problem with the code below which shows images from a folder via mysql database.

The pictures are not correct.

They show as...
pic1 pic2
pic2 pic3
pic4 pic5
pic3 pic6

In addition, There are actually 9 pictures for this page and its only showing 8.

Can anyone please help me with this.

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Location where the images are stored
$file_path = 'http://www.mysite.com/holidays/files/photo_big/';

$sql = mysql_query("SELECT photo_id, photo_caption_1, photo_listing
FROM listing_photo
WHERE photo_listing = 136
ORDER BY `photo_status_main` <> 'main'
LIMIT 10");

if (mysql_num_rows($sql) > 0) {
// Default numver of columns
$num_cols = 2;

while ($row = mysql_fetch_array($sql)) {
$items[] = array('photo_id' => $row['photo_id'], 'photo_caption_1' => $row['photo_caption_1']);
}

// Number of items in the array
$num_items = count($items);

// Number of rows
$num_rows = ceil($num_items / $num_cols);

// Begin HTML table
echo '<table width="70%">';

for ($row = 1; $row < $num_rows; $row++) {
$cell = 0;

// Start each new row
echo '<tr>';

for ($col = 1; $col <= $num_cols; $col++) {
echo '<td>';
if ($col === 1) {
$cell += $row;
echo '<div class="Image"><img src="'. $file_path . $items[$cell - 1]['photo_id'] .'.jpg" alt="'. $items[$cell - 1]['photo_caption_1'] .'" title="'. $items[$cell - 1]['photo_caption_1'] .'" height="213" width="300"/>';
echo '<br />';
echo '<span><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000">'. $items[$cell - 1]['photo_caption_1'] .'</font></span></div>';
}
else {
$cell += $row;
echo '<div class="Image"><img src="'. $file_path . $items[$cell - 1]['photo_id'] .'.jpg" alt="'. $items[$cell - 1]['photo_caption_1'] .'" title="'. $items[$cell - 1]['photo_caption_1'] .'" height="213" width="300"/>';
echo '<br />';
echo '<span><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000">'. $items[$cell - 1]['photo_caption_1'] .'</font></span></div>';
}
echo '</td>';
}
echo '</tr>';
}

echo '</table>';
}
?>

[edited by: tedster at 3:52 am (utc) on Mar 17, 2010]

4:33 am on Mar 16, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


What happened to the original [webmasterworld.com]?

Looks like you have it going fine there, just needed to tweak the CSS a little and it would have worked out . . . . . the code above mixes both and puts it in a table.
9:24 am on Mar 17, 2010 (gmt 0)

New User

5+ Year Member

joined:Mar 10, 2010
posts: 5
votes: 0


Thanks rocknbil

But thats the problem, what do I change in the code to make it work?

Why are the pictures not showing correctly?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members