Re: Stuck with HTML for MySQL Output
| From: | Hugh Bothwell | Date: | Sat, 11 Aug 2001 16:31:16 +0000 |
| Subject: | Re: Stuck with HTML for MySQL Output | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11244@lists.php.net to get a copy of this message | ||
"Red" <mightyred34@hotmail.com> wrote in message
news:20010811134000.50634.qmail@pb1.pair.com...
> I have a very simple query to my mysql dbase which returns the data ok.
But
> I can't get the html to work properly. I can change the bg color, but I
> can't change the font, or font colour
A number of observations:
1. mysql_fetch_array is a bit friendlier to work with.
2. You failed to include the closing bracket on your
table tag
> print "<table border=1 bgcolor=#000099 *** > *** \n";
3. HTML has to be in the <td>...</td>, ie
...<td><b>This is bold</b></td>...
4. If you want to change font or color, you
should consider using CSS classes, ie
<html>
<head>
<style type="text/css">
.myfont {
font-family: Verdana, Arial, sans-serif;
font-size: 12pt;
font-weight: bold;
}
</style>
</head>
<body>
<table>
<tr>
<td>This is normal text</td><td class='myfont'>This is bold
text</td>
</tr>
</table>
</body>
</html>
(to be really pedantic, you should probably use <span></span> around your
text and apply the class to that).
This also goes for your table formatting.
5. If you know your columns ahead of time - and I assume
you do - I would name them explicitly in your code;
this prevents things from jumping around if you
modify your table structure.
> Secondly, how do I get Column titles for my database output?
> I have tried everything and can't work it out.
You have to define the headers explicitly - if you
don't do 'em, you don't get 'em.
// get data
$result = @mysql_query ("SELECT hometeam, awayteam, "
."homescore, awayscore FROM handicap_results")
or die ("<br>Error: ".mysql_error());
// begin table
echo "\n<table border=1 bgcolor=#000099>";
// echo column headers
echo "\n\t<tr><th>Home Team</th>"
."<th>Away Team</th>"
."<th>Hometeam Score</th>"
."<th>Awayteam Score</th></tr>";
while ($row = mysql_fetch_array($result)) {
echo "\n\t<tr>";
foreach($row as $v)
echo "\n\t\t<td>$v</td>";
echo "\n\t</tr>";
}
// close table
echo "\n</table>";