Re: Stuck with HTML for MySQL Output

From: Date: Sun, 12 Aug 2001 18:11:20 +0000
Subject: Re: Stuck with HTML for MySQL Output
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-11269@lists.php.net to get a copy of this message
"Hugh Bothwell" <hugh_bothwell@hotmail.com> wrote in message news:20010811162919.99034.qmail@pb1.pair.com... > "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>"; > Hi Hugh I've been having a look at your code above and if I use it directly from here it fails :( So, I re input it all, and here it is, but there is one problem which you will probably see straight away, as it's not actually bringing the output from the sql dbase, even though it's not failing to connect, or doesn't say there are any errors. Here's the code as I input: <table width="600" border="0" cellspacing="0" cellpadding="5" align="center"> <tr> <td><center><?include ("aokccconnect.inc"); aokcc_db_connect () or exit (); $result = mysql_query ("select * from handicap_results order by victor") or exit (); $num_rows = mysql_num_rows ($result); print " $num_rows games have been played in the League thus far.<p>"; $result = mysql_query ("select victor from handicap_results") or exit ("cannot retrieve data"); echo"\n<table border=1 bgcolor=#000099 cellpadding=5 cellspacing=1>"; echo "\n\t<th>Victor</th>" ."<th>Player 1</th>" ."<th>Player 1 Civ</th>" ."<th>Player 2</th>" ."<th>Player 2 Civ </th>" ."<th>Game Time</th>" ."<th>Game Date</th>" ."<th>Game No</th></tr>"; while ($row = mysql_fetch_row ($result)) { echo "\n\t<tr>"; foreach ($row as $field) "\n\t<td><font face=\"helvetica,arial,sans-serif\">$field</font></td>"; echo "\n\t</tr>\n"; } echo "\n</table>"; ?></center> </td> </tr> </table> if you want to see what it actually does, then here's the url www.oneforme.co.uk/resultstest.php Thanks again for your time. Sara

« previous php.db (#11269) next »