Page 1 of 1
Putting Database Results In A Table
Posted: Mon Aug 21, 2006 11:22 pm
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.
Posted: Mon Aug 21, 2006 11:24 pm
by feyd
Useful Posts, first link.
Posted: Mon Aug 21, 2006 11:40 pm
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 . '"> ' . ";</td>\n</tr>\n\n";
$output .= "</table>\n\n";
$output .= "</DT></P>";
$output .= '</BODY>
</HTML>';
echo $output;
?>
Posted: Mon Aug 21, 2006 11:43 pm
by feyd
...how about those errors?
Posted: Mon Aug 21, 2006 11:45 pm
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
Posted: Mon Aug 21, 2006 11:46 pm
by feyd
Take a look at your query.
Posted: Tue Aug 22, 2006 12:18 am
by nickman013
I got it,
THanks SOOO MUCH!!!