Jump to content

[SOLVED] Display php return in a table


jasonhardwick

Recommended Posts

My page expodes and displays a column of my database (network) right now they are listed like so

 

result 1

result 2

result 3

 

what i want to do is display them like so

 

result 1          result 2          result 3          result 4

 

result 5          result 6          result 7          result 8

 

anyone know what i  can do to get this type of display?

 

 

<?php
include "config.php";
$tbl_name3="user";
$sql3="SELECT * from $tbl_name3 WHERE uname = '{$_SESSION['username']}' ORDER BY id ASC LIMIT 0,1000";
$result3=mysql_query($sql3) or die(mysql_error());
while ($row3 = mysql_fetch_assoc($result3)) {

        $network_id = $row3['network'];
        $network_id_parts = explode(',',$network_id);
        
       foreach ($network_id_parts AS $a_nid_part) {
?>
            </p>
            <p><b><a href="user_profile.php?username=<? echo $a_nid_part; ?>"><? echo $a_nid_part; ?></a></b></p>
            <p>
              <?
		   if (mysql_fetch_assoc($result3) == 0) {
    echo "You Currently Have No Network Connections";
}
                //echo "$a_nid_part ";
        }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/
Share on other sites

Hope this helps:

<?php
require("config.php");

$tbl_name3 = "user";
$sql3 = "SELECT * from $tbl_name3 WHERE uname = '{$_SESSION['username']}' ORDER BY id ASC LIMIT 0,1000";
$result3 = mysql_query($sql3) or die (mysql_error());
if (mysql_fetch_assoc($result3) > 0)
{
while ($row3 = mysql_fetch_assoc($result3))
{
	$network_id = $row3['network'];
	$network_id_parts = explode(",", $network_id);
	if (!empty($network_id))
	{
		echo "<table>";

		$count = 1;
		$limit = 4; // how many results per row
		$early = 0;
		foreach ($network_id_parts AS $a_nid_part)
		{
			$mod = $count % $limit;
			switch ($mod)
			{
				case 0:
					echo "</tr>";
					break;
				case 4:
					echo "<tr>";
					break;
			}
			echo "<td><strong><a href=\"user_profile.php?username={$a_nid_part}\">{$a_nid_part}</a></strong></td>";
			$count++;
			$early = $limit - $mod; // tracking exiting the table early
		}
		// if we left on the $limit column, then just close the row
		if (!$mod)
		{
			echo "</tr>";
			$early = 0;
		}
		// if we left before the $limit column, fill in blank cells to have a proper table
		if ($early)
		{
			for ($i = 1; $i <= $early; $i++)
			{
				echo "<td> </td>";
			}
			echo "</tr>";
		}
		echo "</table>";
	}
	else
	{
		echo "You Currently Have No Network Connections";
	}
}
}
else
{
echo "You Currently Have No Network Connections";
}
?>

 

I changed a few things too, just my $0.02:

1. include to require since config.php seems to be your db connection. You don't want to keep processing the page if you can't connect and require will stop.

 

2. move the check for no connections to before making the table. if you don't have any, no need to start trying.

 

3. few other little things. should be fairly obvious.

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.