SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 22nd, 2004, 06:00 AM
Morrowind Morrowind is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Finland
Posts: 7 Morrowind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to Morrowind
Question Problem with table creating loop for MySQL results

My target is this: retrieve from the database LIMIT 10 images and show the images in HTML-table, where is 5 columns and two rows. If there are not 10 images, showing default image in the table after the images, which found.

My code works fine if images found in the table 1-4 items. But if images found 5 or more, the HTML-table does not work. Columns are only four and images after fourth are printed to the one column, and default images go to to the bottom of the table ugly.

I have tried to solve this multiple times, but I have had not success so far.I think the bug must be quite small thing in my while or for loop, but I cannot find out. Could someone find the solution, I'd be more than happy.


PHP Code:
<?php
require_once "conn.php"
 
/*
If for instance 7 images, then showing default image three 
times after the images that found (this is my 
 
target)
*/
 
 
 
 
$LIMITED=10//Limit value
$cols 5;//setting number of columns for the table
$j 1//for columns of the table
$i 0
//$i is for default image in the loop that calculates how many times default image is shown
 
 
$result mysql_query ("SELECT id,thumb_image FROM imagetable LIMIT $LIMITED");
 
$sum mysql_num_rows($result); //how many results
 
//works fine if < 5 images found, but 5 or more does not
 
echo "<table border=0 cellpadding=4 cellspacing=4>";
echo 
"<tr>";
 
 
while (
$row mysql_fetch_array($result)) {
if (
is_int($j $cols)){     
 
echo 
"\n</tr><tr><td>";
 
echo 
"<a href=show_img.php?id={$row['id']} Target=_self>";
echo 
"<img src=pictures/".$row['thumb_image']." border=0></a>";
 
 
echo 
"</td></tr><tr>";
}
 
 
else 

echo 
"<td>";
 
echo 
"<a href=show_img.php?id={$row['id']} Target=_self>";
echo 
"<img src=pictures/".$row['thumb_image']." border=0></a>";
 
echo 
"</td>";         
 
}
//else ends
     
$j++;
 
 
     } 
//while ends
 
/*
Calculating how many times default image must be shown 
*/
 
for ($i 0;$i < ($LIMITED $sum);$i++){
 
     if (
is_int($i $cols))
     {     
 
 
    echo 
"<td>";         
 
    echo 
"<img src=\"images/default.jpg\">";         
 
    echo 
"</td></tr><tr>";
     }
 
else 
        {
 
echo 
"<td>";
echo 
"<img src=\"images/default.jpg\">";     
echo 
"</TD>"
 
}
 
}
//for ends
 
 
echo "</tr>";
echo 
"</table>";
 
echo 
"</body>";
echo 
"</html>";
?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Problem with table creating loop for MySQL results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway