Help Formatting PHP MySql output
Posted: Tue Feb 16, 2010 12:16 pm
Hi New to PHP and MySql. I have built the following PHP from a few different places. The script outputs all entries in my database to a table with headers. What I would like to do is format the output to make it look nice. This is where i need some guidance.
I would like the table Headers to be white text and black background and the date in the table to be 10 point Verdana with a rule between each entry.
I have pasted the code below. Any help would be great.
Cheers Chris
<?
$username="mydetails";
$password="fmydetails";
$database="mydetails";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM cbs WHERE name='$_POST[name3]'";
$result=mysql_query($query);
if (($result)||(mysql_errno == 0))
{
echo "<table width='100%'><tr>";
if (mysql_num_rows($result)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
while ($i < mysql_num_fields($result))
{
echo "<th>". mysql_field_name($result, $i) . "</th>";
$i++;
}
echo "</tr>";
//display the data
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center' >". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>Sorry No Results found!</td></tr>";
}
echo "</table>";
}else{
echo "Error in running query :". mysql_error();
}
?>
I would like the table Headers to be white text and black background and the date in the table to be 10 point Verdana with a rule between each entry.
I have pasted the code below. Any help would be great.
Cheers Chris
<?
$username="mydetails";
$password="fmydetails";
$database="mydetails";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM cbs WHERE name='$_POST[name3]'";
$result=mysql_query($query);
if (($result)||(mysql_errno == 0))
{
echo "<table width='100%'><tr>";
if (mysql_num_rows($result)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
while ($i < mysql_num_fields($result))
{
echo "<th>". mysql_field_name($result, $i) . "</th>";
$i++;
}
echo "</tr>";
//display the data
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center' >". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>Sorry No Results found!</td></tr>";
}
echo "</table>";
}else{
echo "Error in running query :". mysql_error();
}
?>