How to pull multi-dimensional array from database and display in 4 columns & 8 rows? I have been stressing over the display. I have 30 records in the database and want to display the items into 4 columns and 8 rows. I have tried changing codes many times and sometimes, it will display only one record or only the first row(4 records). Can someone please tell me what went wrong?
Here is my code:
================================================== =
$conn = mysql_connect("localhost","user","password")or die(mysql_error());
mysql_select_db("database",$conn);
$query="SELECT P_ID, StNo, Street, City, PropertyType, Bedrooms, Bathrooms, AskPrice FROM properties";
$rs = mysql_query($query, $conn) or die(mysql_error());
$i= mysql_num_rows($rs);
if ($i<1)
{
$display="<p> You have no property </p>";
}
else
{
echo "$i";
$display="<table width='60%' border='1'>";
$w=4;
$j=0;
$row = array();
while ($resultrow = mysql_fetch_assoc($rs))
{
$row[] = $resultrow;
while (($w<30)&& ($i>0))
{ $display.="<tr>";
while ( ($j < $w) &&($w<30))
{
print_r($row[$j]);
$pid=$row[$j]['P_ID'];
$stno=$row[$j]['StNo'];
$stname=$row[$j]['Street'];
$city=$row[$j]['City'];
$propertytype=$row[$j]['PropertyType'];
$bedrooms=$row[$j]['Bedrooms'];
$bathrooms=$row[$j]['Bathrooms'];
$askprice=$row[$j]['AskPrice'];
$display.="<br>Row [$j] [PID]: $pid";
$display.="<td>$pid <br>
$stno $stname, $askprice<br>
$city</td>";
echo "<br>Inside the loop<br>j: $j";
echo "i with j: $i";
$j++;
} $display.="</tr>";
$w= $w+4;
}
}
$display.="</table>";
mysql_free_result($rs);
mysql_close($conn);
}
==============the end=======================================