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? Link to comment https://forums.phpfreaks.com/topic/36343-bit-of-trouble/ 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] Link to comment https://forums.phpfreaks.com/topic/36343-bit-of-trouble/#findComment-172791 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 Link to comment https://forums.phpfreaks.com/topic/36343-bit-of-trouble/#findComment-172797 Share on other sites More sharing options...
ted_chou12 Posted January 30, 2007 Share Posted January 30, 2007 boo_lolly is faster :DTed Link to comment https://forums.phpfreaks.com/topic/36343-bit-of-trouble/#findComment-172798 Share on other sites More sharing options...
ki Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks the first one worked fine Link to comment https://forums.phpfreaks.com/topic/36343-bit-of-trouble/#findComment-172806 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. Link to comment https://forums.phpfreaks.com/topic/36343-bit-of-trouble/#findComment-172807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.