Jump to content

[SOLVED] wierd behavior...


nathanmaxsonadil

Recommended Posts

my loop is acting wierd...

here's the php code

$sql1 = mysql_query('SELECT * FROM table ORDER BY id DESC') or die('Could not connect: ' . mysql_error());
$numrows = mysql_num_rows($sql1);
$numrows = $numrows / 2;
$numrows = round($numrows);
echo '<div id="content"><div id="columnsC">';
$i = 0;
while ($row = mysql_fetch_assoc($sql1)) {
$i++;
if($i = $numrows){
echo'</div>
<div id="columnsD">';
}
echo "<a href='{$row['href']}'>
<img style='border:0;' src='siteimg/{$row['img']}' alt='{$row['alt']}'/>
{$row['url']}
</a>";
}
echo'</div>';

here's what the html should be

<div id="content"><div id="columnsC"><a href='site1.php'>
<img style='border:0;' src='siteimg/site1.jpg' alt='site1'/>
site1.com
</a><a href='site2.php'>
<img style='border:0;' src='siteimg/site2.jpg' alt='site2'/>
site2.com
</a></div>
<div id="columnsD"><a href='site3.php'>
<img style='border:0;' src='siteimg/site3.jpg' alt='site3'/>
site3.com
</a></div>

however this is what the html is

<div id="content"><div id="columnsC"></div>
<div id="columnsD"><a href='site1.php'>
<img style='border:0;' src='siteimg/site1.jpg' alt='site1'/>
site1.com
</a></div>
<div id="columnsD"><a href='site2.php'>
<img style='border:0;' src='siteimg/site2.jpg' alt='site2'/>
site2.com
</a></div>
<div id="columnsD"><a href='site3.php'>
<img style='border:0;' src='siteimg/site3.jpg' alt='site3'/>
site3.com
</a></div>

what's wrong with my code?

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.