AIS4U,
What I am doing, that is an interesting question. My overall goal is to create a table that will fetch multiple rows from a database and show them in a neat organized table that I can portray in a website. I want to be able to alternate coloring in the table with white and gray background. Late last night I was actually successful in my first part of my task and that is to get data from the database using this code. I was introduced to this type of code through a book called PHP5 and Mysql5: From novice to professional. I adapted the code though because I prefer using Mysql not mysqli. The code I finally got to work last night is below. This might be a really bad way at doing this and I am new to to using PHP and Mysql, I started learning when our IT department bascially said they don't help in writing web pages. If there is an easier way to acheive my overall goal that would be great. As it is now I still have to add links to the table that I will have to create and make it so the table is neat and evenly spaced.
I am very new to this and sorry for the confusion but I am basically trying to teach myself very quickly to meet some application deadlines.
With this code I can retrieve the data from the database but the alternate styling does not work and the alternate row coloring does not work.
Again anything to make this easier would help tremendously
THanks
Yanks6rule
<?php
include "HTML/Table.php";
mysql_connect('host', 'user', 'password') or exit(mysql_error());
mysql_select_db('database') or exit(mysql_error());
$table = new HTML_Table();
$table->setHeaderContents(0, 0, "Last Name");
$table->setHeaderContents(0, 1, "First Name");
$table->setHeaderContents(0, 2, "E-mail Address");
$table->setHeaderContents(0, 3, "Advisor");
$table->setHeaderContents(0, 4, "Graduation Year");
$table->setHeaderContents(0, 5, "Highest Degree");
$table->setHeaderContents(0, 6, "Attending");
$query = "SELECT lastname, firstname, email,
advisor, year, degree, attend FROM rsvp
ORDER BY firstname";
$result = mysql_query($query) or exit(mysql_error());
$rownum = 1;
// Format each row
while ($row = mysql_fetch_object($result)) {
$table->setCellContents($rownum, 0, $row->lastname);
$table->setCellContents($rownum, 1, $row->firstname);
$table->setCellContents($rownum, 2, $row->email);
$table->setCellContents($rownum, 3, $row->advisor);
$table->setCellContents($rownum, 4, $row->year);
$table->setCellContents($rownum, 5, $row->degree);
$table->setCellContents($rownum, 6, $row->attend);
$rownum++;
}
// Alternate row styling
$table->altRowAttributes(1, null, array("class"=>"alt"));
// Output the data
echo $table->toHTML();
mysql_close();
?>