homepage Welcome to WebmasterWorld Guest from 54.167.177.180
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Small php sql help
php,sql
mladams



 
Msg#: 4097827 posted 8:18 am on Mar 15, 2010 (gmt 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]

 

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4097827 posted 4:33 am on Mar 16, 2010 (gmt 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.

mladams



 
Msg#: 4097827 posted 9:24 am on Mar 17, 2010 (gmt 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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved