Dynamic HTML table multiple columns

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
eraxian
Forum Newbie
Posts: 1
Joined: Mon Mar 24, 2008 4:50 pm

Dynamic HTML table multiple columns

Post by eraxian »

Hello, pretty new to PHP here so sorry if my problem is noobish. Well i'm sure it is, but anyway.

Basically I have a table w/ 2 fields in a mysql database. On my site i have a table of letters, and when the user clicks a letter, it creates an html table w/ the names from the database that start w/ that letter.

All i'm trying to do is figure out how to make that table have multiple columns w/o repeating the same record from the database. Might be a nested loop is needed, i'm not sure how to implement it though. here is the code so far for it.

Code: Select all

 
<?php
...
 
$result = mysql_query("SELECT * FROM list WHERE name LIKE 'A%' ORDER BY name");
 
echo "<table border='1'>
<tr>
<th>Bands</th>
</tr>";
 
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . "<a href=\"/bands/list/" . $row['link'] . ".html\">" . $row['name'] .  "</a>" . "</td>";
  echo "</tr>";
  }
echo "</table>";
 
mysql_close($con);
?>
 
thanks for any help!
samb0057
Forum Commoner
Posts: 27
Joined: Wed Mar 26, 2008 9:51 am

Re: Dynamic HTML table multiple columns

Post by samb0057 »

while($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td>';
echo $row['name'];
echo '</td>';
echo '<td>';
echo $row['link'];
echo '</td>';
echo '</tr>';
}

Or, to display all values in the result in no particular order.

while($row = mysql_fetch_array($result)) {
echo '<tr>';
foreach ($row as $value) {
echo '<td>';
echo $value;
echo '</td>';
}
echo '</tr>';
}
Post Reply