Jump to content

bit of trouble


ki

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.