krv Posted January 21, 2009 Share Posted January 21, 2009 hello I have an upload script that uploads a file to a directory on my site once the file is uploaded it saves the file name as a reference point in mysql also a category is added. I am trying to show the images by category but am having trouble limiting to 3 cells per row while in a loop from mysql_result example: while($row=mysql_fetch_array($result){ echo " <tr> <td><img src='images/$row[filename][1]></td> <td><img src='images/$row[filename][2]></td> <td><img src='images/$row[filename][3]></td> </tr> <tr> <td><img src='images/$row[filename][4]></td> <td><img src='images/$row[filename][5]></td> <td><img src='images/$row[filename][6]></td> </tr> } and so on.... so i guess im stuck on creating and limiting an array and count rows per category. Thanks <?php $sqlimg = "SELECT id,category FROM ht_img WHERE category='$_POST[cat]'"; $imgresult = mysql_query($sqlimg)or die(mysql_error()); ?> <table cellspacing="0" style="width: 100%;text-align: center;"> <?php while ($row=mysql_fetch_array($imgresult)){ $img = $row['name']; $tablerows = " <tr> <td $tddisplay><img src=\"img/$img\" class=\"appdata-img\" /> <br /><input type=\"radio\" name=\"template\" /></td> <td $tddisplay><img src=\"img/$img\" class=\"appdata-img\" /> <br /><input type=\"radio\" name=\"template\" /></td> <td $tddisplay><img src=\"img/$img\" class=\"appdata-img\" /> <br /><input type=\"radio\" name=\"template\" /></td> </tr>"; echo $tablerows; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/141797-solved-mysqlphp-limiting-display-with-images/ Share on other sites More sharing options...
krv Posted January 21, 2009 Author Share Posted January 21, 2009 Does anyone have any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/141797-solved-mysqlphp-limiting-display-with-images/#findComment-742614 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 Don't mark a thread "solved" without posting the solution. Quote Link to comment https://forums.phpfreaks.com/topic/141797-solved-mysqlphp-limiting-display-with-images/#findComment-747505 Share on other sites More sharing options...
krv Posted March 4, 2009 Author Share Posted March 4, 2009 solution $number_of_thumbs_in_row = 3; $result = mysql_query(" SELECT id,name, FROM img "); $nr = mysql_num_rows($result); if (empty($nr)) $result_final = "\t<tr><td>No images found</td></tr>\n"; else { while ($row = mysql_fetch_array($result)) { $result_array[] = "<img src=\"images/$row[name]\" border=\"0\" />"; } mysql_free_result($result); $result_final = "<tr>\n"; foreach ($result_array as $thumbnail_link) { if ($counter == $number_of_thumbs_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td class=\"appdata-image-ol\">" . $thumbnail_link . "</td>\n"; } if ($counter) { if ($number_of_photos_in_row - $counter) $result_final .= "\t<td colspan='" . ($number_of_photos_in_row - $counter) . "'> </td>\n"; } $result_final .= "</tr>"; } echo $result_final; Quote Link to comment https://forums.phpfreaks.com/topic/141797-solved-mysqlphp-limiting-display-with-images/#findComment-776514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.