Formatting PHP Output

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
MikeX
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2008 8:50 am

Formatting PHP Output

Post by MikeX »

Hey all


I've been trying to format my PHP output on my script. So far I can do three things... Bold Italic Underline using b i u but thats it.. I have no clue how to use color or font or anything.

Any ideas? It would be ideal to be able to have no border.. which I know how to do.. and have alternating font/text backing color for each row.

Here's my script:

Code: Select all

 
<?php
  include('dbconnect.php');
?><style type="text/css">
<!--
body {
 
}
-->
</style>
...
 
<?php
 // Get all the data from the "Groups" table
$result = mysql_query("SELECT * FROM Groups") 
or die(mysql_error());  
 
echo "<table border='1'>";
echo "<tr> <th><b>University</b></th> <th>Group</th> <th>State</th> <th>Zip Code</th> <th>Website</th> <th>Email</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td>"; 
    echo $row['University_Name'];
    echo "</td><td>"; 
    echo $row['Group_Name'];
    echo "</td><td>"; 
    echo $row['State'];
    echo "</td><td>"; 
    echo $row['Zipcode'];
    echo "</td><td>"; 
    echo $row['Website'];
    echo "</td><td>"; 
    echo $row['Email'];
        echo "</td></tr>";
} 
 
echo "</table>";
?>
 
MikeX
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2008 8:50 am

Re: Formatting PHP Output

Post by MikeX »

Ooops.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Formatting PHP Output

Post by Christopher »

To remove the border change echo "<table border='1'>"; to echo "<table border='0>";. To alternate rows you can to switch back and forth between colors using PHP, or you have use a Javascript library to change the output once the document loads.
(#10850)
MikeX
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2008 8:50 am

Re: Formatting PHP Output

Post by MikeX »

Code: Select all

.white{
font-color:#12ff56
background-color:#ffffff;
font-size:12px;
}
 
.blue{
font-color:#ffffff
background-color:#12ff56;
font-size:12px;
}

Code: Select all

<?php
  include('dbconnect.php');
?><link href="custom.css" rel="stylesheet" type="text/css">
<!--
body {
 
}
-->
</style>
...
<?php
 // Get all the data from the "Groups" table
$result = mysql_query("SELECT * FROM Groups") 
or die(mysql_error());  
$num='0';
 
echo "<table border='1'>";
echo "<tr> <th><b>University</b></th> <th>Group</th> <th>State</th> <th>Zip Code</th> <th>Website</th> <th>Email</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr>"; 
 
if ($num%2=='1') { 
echo "<td class='white'>"; 
} else { 
echo "<td class='blue'>"; }
 
    echo $row['University_Name'];
    echo "</td><td>"; 
    echo $row['Group_Name'];
    echo "</td><td>"; 
    echo $row['State'];
    echo "</td><td>"; 
    echo $row['Zipcode'];
    echo "</td><td>"; 
    echo $row['Website'];
    echo "</td><td>"; 
    echo $row['Email'];
        echo "</td></tr>";
$num++;
} 
 
echo "</table>";
?>
I placed the css file in the directory.. and it changes the font style on the University column but nothing else.. no color or font changes.
Post Reply