I've this search where each result takes 1 row. Now i want 3 results to take one row and if there's more than 3 results , 2nd row is created and so on. Please help
quick, dirty method
$i = 0; echo "<table>\n"; $query_st = "SELECT * FROM table"; $query_rs = mysql_query($query_st); while($query_ar = mysql_fetch_array($query_rs)) { switch($i) { case "0": echo "<TR><TD>$query_ar[field]</TD>\n"; break; case "1": echo "<TD>$query_ar[field]</TD>\n"; break; case "2": echo "<TD>$query_ar[field]</TD></TR>\n"; $i=0; break; } } if($i != 2) echo "</TR>"; echo "</TABLE>";
no luck your code did not work
Well, is your query pulling out any fields at all? What's it displaying now?
Use something like this
$i = 0; while something { if ($i == 2) { echo "<tr>"; } echo "<td> blah 1</td>" echo "<td> blah 2</td>" echo "<td> blah 3</td>"
$i++;
if ($i == 3) { echo "</tr>"; $i = 0; } }