Hi, I am trying to create rows and columns for some data but it is misbehaving, ie, creating one row with 6 columns instead of 'n' rows with only three columns each. Any help will be greatly appreciated. Here is the code:
<? $query = "SELECT * FROM friends WHERE friendid = '".$_SESSION['user_id']."' AND allow = 1 ORDER BY first_name ASC";
$result = mysql_query($query) or die ("Query failed");
//get the number of rows in our result so we can use it in a for loop
$numrows = (mysql_num_rows ($result));
echo "<table width = 100% border = '0' cellspacing = '2' cellpadding = '0'>";
// loop to create rows
if($numrows >= 1){
for ($r = 0; $r <= $numrows; $r++) {
echo "<tr>";
// loop to create columns
while ($friendList = mysql_fetch_array($result)) {
for ($c = 0; $c <= 2; $c++) {
echo "<td><a href='memberindex.php?id = ".$friendList['id']."'><img src='".$friendList['friendImg']."' title='".$friendList['first_name']."' alt='".$friendList['first_name']."'/><br />".$friendList['first_name']."</a><br /></td> "; }}
echo "</tr> "; }}
<? echo "</table> "; ?>