tags:

views:

52

answers:

3

hey guys , i know this is a stupid question but i hanged in solving it

i wrote a block of php code to show images from mysql

    echo "<table><tr> ";

    while($cat = $db->sql_fetchrow($catinfo)) {
        echo '
        <td>
        <ul id="three-col" class="press">   
        <li>
    <div class="post-content">
    <a class="zoom1" href="'.$galsettings[setImgDir].'/'.$cat[galCatLocation].'/'.$cat[galCatImg].'">
    <img src="'.$galsettings[setImgDir].'/'.$cat[galCatLocation].'/'.$cat[galCatImg].'" alt="artistry (via powerbooktrance)" />
    </a>
    </div>';

    for ($i=0; $i>2; $i++) {
    echo "</tr><tr>";
    }
    }

echo "</li></ul></td></tr></table>";

but with this code everything goes wrong and it doesnt break after each 3 images in row

i even used

if ($i>2) {
    echo "</td></tr><tr>";
}

but as u know it only breaks the tr after image number 3 not every row

im really sorry for my foolish question

A: 

Where's you're </td> tag?

All your TDs have to be inside the TRs. You have to close the UL and TD before your TR.

Nathan
+2  A: 

First off, the

  for ($i=0; $i>2; $i++) {

should probably be

for ($i=0; $i < 2; $i++) {

There may be additional logic issues (looking)...

Indeed the logic seems utterly flawed, for ex. there doesn't appear to be anything which detects the the third image etc...

==> I suggest you try the snippet from tambler's answer. No point in trying and fix this one... but if you must:

  • the for ($i=0; $i>2; $i++) { loop is unnecessary. Even when fixed to $i < 2 (or 3...) this doesn't do anything useful.
  • with each new image you output a <td>, this needs to be closed with a </td>
  • there need to be a counter (the $i) you hint at in your snippet isn't valid
  • the counter is to be systematically incremented with each image
  • a test is to be added towards the end of the loop:
    If counter >= 3 (or 2, if you make it 0-based) reset counter; emit ""
  • Also the <ul> and <li> and their respective closing tags are misplaced.
mjv
i respect ur answer that was something , but bro that was not so clear for beginers like me
Yvette
+2  A: 

Try this:

echo "<table><tr> ";

$counter = 0;

while($cat = $db->sql_fetchrow($catinfo)) {

    $counter++;

    echo '
    <td>
    <ul id="three-col" class="press">   
    <li>
    <div class="post-content">
    <a class="zoom1" href="'.$galsettings[setImgDir].'/'.$cat[galCatLocation].'/'.$cat[galCatImg].'">
    <img src="'.$galsettings[setImgDir].'/'.$cat[galCatLocation].'/'.$cat[galCatImg].'" alt="artistry (via powerbooktrance)" />
    </a>
    </div>
    ';

    if ( $counter == 3 ) {

        echo '</tr><tr>';

        $counter = 0;
    }

}

echo "</li></ul></td></tr></table>";
tambler
yeah, you probably want to move `</li></ul></td>` right after the `</div>`
Nathan
that was really smart my friend , love u
Yvette
I love you, too.
tambler
hey bud , i got a new problem , look at here :http://mahlaghabonbon.com/in IE doesnt show 3images in row
Yvette