pratkal Posted July 8, 2011 Share Posted July 8, 2011 Hi how can i do this in phpI want to create table from PHP result with 4 rows / cols after that a new row i.e if there is 4 result there there will be 1 cols and 4 rows while if there is 5 result then 2 cols and 4 rows i am using while($row = ) to fetch the result from mysql table Link to comment Share on other sites More sharing options...
thescientist Posted July 8, 2011 Share Posted July 8, 2011 Hi how can i do this in phpI want to create table from PHP result with 4 rows / cols after that a new row i.e if there is 4 result there there will be 1 cols and 4 rows while if there is 5 result then 2 cols and 4 rows i am using while($row = ) to fetch the result from mysql tableI don't really follow that part, but you should read the tutorials, there are examples in the PHP/MySQL section.http://www.w3schools.com/php/php_mysql_select.asp Link to comment Share on other sites More sharing options...
pratkal Posted July 8, 2011 Author Share Posted July 8, 2011 while ($row = mysql_fetch_assoc($result)) { $i=1; while($i<=5) { if($i=='1'); { echo '<tr>'; echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; } if($i<='4'); { echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; } if($i=='5'); { echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; echo '</tr>'; this code i used but gone to infinite loop lol Link to comment Share on other sites More sharing options...
pratkal Posted July 8, 2011 Author Share Posted July 8, 2011 1 step ahead echo'<table width="100%" border="0">'; $i=1; while($i<=3) { while ($row = mysql_fetch_assoc($result)) { if($i='1'); { echo '<tr>'; echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; $i=2; } if($i=='2'); { echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; $i=3; } if($i=='3'); { echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; echo '</tr>'; } now how to exit the code when my sql associated row run out of? Link to comment Share on other sites More sharing options...
thescientist Posted July 9, 2011 Share Posted July 9, 2011 1 step ahead echo'<table width="100%" border="0">'; $i=1; while($i<=3) { while ($row = mysql_fetch_assoc($result)) { if($i='1'); { echo '<tr>'; echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; $i=2; } if($i=='2'); { echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; $i=3; } if($i=='3'); { echo '<td width="25%" style="text-align: center">'; echo $row['cat']; echo '</td>'; echo '</tr>'; } now how to exit the code when my sql associated row run out of? err.... why are you using two loops? did you look at the example at the bottom of the link I posted? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.