hi, i want to display 2 or more records per row. in asp it's working fine. this is the asp code for 3 records per row: <table> <tr> <% while not RS.EOF %> <% if count mod 3 = 0 then response.write("</tr><tr>") end if%> <td width="33%" align="center" valign="bottom" bgcolor="#f7ffff"><%=RS("product_name")%></td> <%count = count + 1 RS.MoveNext WEND%> </tr> </table> HTML: can anyone convert this to php? thanks in advance!
$con = mysql_connect("localhost","username","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $result=mysql_query("select * from table"); $num_rows = mysql_num_rows($result); $count=0; echo "<table><tr>"; if ($num_rows>0) { while($row = @mysql_fetch_array($result)){ if (count % 3 == 0) echo("</tr><tr>"); echo " <td width=\"33%\" align=\"center\" valign=\"bottom\" bgcolor=\"#f7ffff\">".$row["product_name"]."</td>"; $count = $count + 1; } } mysql_close($con); }
you want this: <table> <tr> <?php $select = mysql_query("SELECT * FROM `news`"); while($row = mysql_fetch_array($gamedt)){ $news = $row['news']; ?> <td width="16%"><div align="center"><? echo $news; ?></td> <? if (++$rowcount % 2 == 0) { echo '</tr><tr>'; } } ?> </tr> </table> PHP: