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
https://forums.phpfreaks.com/topic/69378-solved-wierd-behavior/
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.