Jump to content

Need a basic help


pratkal

Recommended Posts

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

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
I 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

	 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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...