Putting Database Results In A Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Putting Database Results In A Table

Post by nickman013 »

Hello,

I need help getting database information to be displayed using tables. I know how to make a single column table, but I want to make two columned tables with multiple rows.

For example if there was 6 things that I want to display from the table, it would look like this.

1 - 2
___
3 - 4
____
5 - 6


The - correspond with the seperate columns, and the __ corresponds with seperate rows.

Thank you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Useful Posts, first link.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Thanks for replying so quickly feyd.

I went to the post with the information on how to do it, and I tried. But I get errors.

My code.

Code: Select all

<?php 
MY DATABASE STUFF IS HERE.

# connect to database 
$cid = mysql_connect($host,$usr,$pwd); 
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } 

$output = '<HTML> 
<HEAD> 
<TITLE>Previous Muots</TITLE> 
</HEAD>'; 

# setup SQL statement 
$SQL = " SELECT * FROM code * WHERE previous = '1'"; 
$SQL = $SQL . 

# execute SQL statement 
$retid = mysql_db_query($db, $SQL, $cid) or die(mysql_error()); 

# display results 
$output .= "<P><DT><B>Previous Muots</B><BR>\n\n"; 
$output .= "<table>\n\n"; 
$howmany = mysql_num_rows($retid); 
$rowmax = 3; 
for($x = 0; $row = mysql_fetch_array($retid); $x++) 
{ 
if($x % $rowmax == 0) 
$output .= "<tr>\n"; 
$prevpic = $row["prevpic"]; 
$prevname = $row["prevname"]; 


$output .= "<td><img src =\"prevpics/$img_name\"><br>$prevname</td>"; 
if($x % $rowmax == $rowmax - 1) 
$output .= "\r</tr>\n\n"; 
} 

if($left = (($howmany + $rowmax - 1) % $rowmax)) 
$output .= '<td colspan="' . $left . '">&nbsp' . ";</td>\n</tr>\n\n"; 

$output .= "</table>\n\n"; 

$output .= "</DT></P>"; 

$output .= '</BODY> 
</HTML>'; 

echo $output; 
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

...how about those errors?
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Woops I forgot to put them in, the page looks like this when I go to it.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/muot/public_html/prevmuots.php on line 26

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/muot/public_html/prevmuots.php on line 28
Previous Muots
&nbsp;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Take a look at your query.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I got it,

THanks SOOO MUCH!!!
Post Reply