Jump to content

bit of trouble


ki

Recommended Posts

Okay what im trying to do is grab images from my database and displaying them in a table, so I want something like

1 2 3 4
5 6 7 8

like showing the users images he has uploaded, and puting them into 4 images per rows, you see what im saying?
Link to comment
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.