ki Posted January 30, 2007 Share Posted January 30, 2007 Okay what im trying to do is grab images from my database and displaying them in a table, so I want something like1 2 3 45 6 7 8like showing the users images he has uploaded, and puting them into 4 images per rows, you see what im saying? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 this is pretty easy.[code]<?php $sql = "SELECT * FROM your_table WHERE photo != ". NULL .""; $query = mysql_query($sql) OR die(mysql_error()); $i = 0; echo "<table><tr>\n"; while($row = mysql_fetch_array($query)){ if($i % 4 == 0){ echo "</tr><tr>\n"; } echo "<td>Img Name: ". $row['imgname'] ."</td>\n"; $i++; } echo "</table>\n";?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 30, 2007 Share Posted January 30, 2007 if yours is mysql[code]<table><?php$read = 0;while ($row = mysql_fetch_array($result) {if ($read % 4 = 0) {echo "<tr>";}echo "<td><img src=\"your images\"></td>"; if ($read % 4 = 3) {echo "</tr>";}$read ++;}?></table>[/code]Since <tr> is really the only component which decides where to change row, so i did a modulus, starting with 0/4 the remainder is 0, the next starting row component: 4/4 remainder is 0, so each time remainder is 0 starts with a new <tr> tag, while same is true for </tr>.[table][tr][td]0[/td][td]1[/td][td]2[/td][td]3[/td][/tr][tr][td]4[/td][td]5[/td][td]6[/td][td]7[/td][/tr][/table]can you already see an arithmatic pattern?each time row starts, divded by 4, the remainder is always 0, while the end of each row is always 3.Ted Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 30, 2007 Share Posted January 30, 2007 boo_lolly is faster :DTed Quote Link to comment Share on other sites More sharing options...
ki Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks the first one worked fine Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 no problem bud. i'm glad we could get you pointed in the right direction. Quote Link to comment 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.