PDA

View Full Version : Data Base Help



mlowery
June 23rd, 2003, 22:15
I have inserted all of my information into my data base. Now I want to print it onto my website. I know how to get it to print onto my website, but I don't know how to organize it. I want to print the information into an HTML table, and I want the table rows to alternate colors. Also I want to adjust font, how would I do this?

dawizman
June 23rd, 2003, 22:48
here is a basic template:

I am too tired right now to think of how to do the alternating colors, but I'm sure someone else can figure that one out. It should be just as easy as a while loop
mySQL table:



Name = Stuff

Colums = first_name, last_name



php code:



<?PHP

$host = ""; //Hostname, usually localhost
$user = ""; //Database Username
$pass = ""; // Password For Above User
$db = ""; //Name Of Database
$connect = mysql_connect($host, $user, $pass);
mysql_select_db($db, $connect);

//define variables

$stuff = mysql_query("SELECT * FROM stuff ORDER BY name ASC");

//display stuff

echo "<TABLE>";
echo "<TR>";
echo "<TD>";
while($row = mysql_fetch_array($stuff) )
{
echo "$row['first_name']</TD><TD>$row['last_name']</TD>";
}
echo "</TR>";

?>

keith
June 24th, 2003, 00:15
to alternate bgcolor:
<?php

echo "<TABLE>";
while($row = mysql_fetch_array($stuff) ) {

if (!isset($bgcolor) || $bgcolor == "#EEEEEE") $bgcolor = "#CCDEEE";
else $bgcolor = "#EEEEEE";

echo "<tr><td bgcolor=\"".$bgcolor."\">Info here</td></tr>";

}
echo "</TABLE>";

?>