Jump to content

Generating Dynamic HTML Table While Displaying MySQL Data


jamesjmann

Recommended Posts

Hi, I'm trying to make a dynamic html table to contain the mysql data that is generated via php. I'm trying to display a user's friends in a table of two columns and however many rows, but can't seem to figure out what is needed to make this work.

 

Here's my code as it stands:

<?php
					//Begin mysql query
					$sql = "SELECT * FROM friends WHERE username = '{$_GET['username']}' AND status = 'Active' ORDER BY friends_with ASC";
					$result = mysql_query($sql);
					$count = mysql_num_rows($result);

					$sql_2 = "SELECT * FROM friends WHERE friends_with = '{$_GET['username']}' AND status = 'Active' ORDER BY username ASC";
					$result_2 = mysql_query($sql_2);
					$count_2 = mysql_num_rows($result_2);

					while ($row = mysql_fetch_array($result)) {
                                                          echo $row["friendswith"] . "<br>";
                                                }
					while ($row_2 = mysql_fetch_array($result_2)) {
                                                          echo $row_2["username"] . "<br>";
                                                }
?>

 

The above simply outputs all records of a user's friends (their usernames) in alphabetical order. The question of how I'd generate a new row each time a certain amount of columns have been met, however, is beyond me. Anyone know of any helpful resources that may solve my problem? Thanks in advance =)

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.