nathanmaxsonadil Posted September 14, 2007 Share Posted September 14, 2007 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 More sharing options...
wildteen88 Posted September 14, 2007 Share Posted September 14, 2007 Change this line: if($i = $numrows){ to: if($i == $numrows){ Link to comment https://forums.phpfreaks.com/topic/69378-solved-wierd-behavior/#findComment-348597 Share on other sites More sharing options...
nathanmaxsonadil Posted September 14, 2007 Author Share Posted September 14, 2007 lol thanks Link to comment https://forums.phpfreaks.com/topic/69378-solved-wierd-behavior/#findComment-348604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.