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 =)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.