RE: [PHP-DB] Stuck with HTML for MySQL Output
| From: | BoNzO | Date: | Sat, 11 Aug 2001 16:57:07 +0000 |
| Subject: | RE: [PHP-DB] Stuck with HTML for MySQL Output | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11245@lists.php.net to get a copy of this message | ||
I was thinking about writing a little howto when extracting data from
mysql
First I always connect to the server
Mysql_connect("$server","$userid","$passwd");
Mysql_select_db("$database");
Then I define my query in variable $sql
$sql = "SELECT
FirstName
,LastName
FROM
Users";
Then I run the query
Mysql_query("$sql");
If I get any error I can Easley run
Print $sql;
To verify my sqlcode (it can easly be some errors when having variables
in a query)
Then for easy count I do
$num = mysql_numrows($result);
It will return the amount of rows from the query
Then its just to extract the data.
If ($num) {
$html = "<table>\n";
$html.= "\t<tr>\n";
$html.= "\t\t<td>Firstname</td>\n";
$html.= "\t\t<td>Lastname</td>\n";
$html.= "\t</tr>\n";
While ($row = mysql_fetch_array($result)) {
$html.= "\t<tr>\n";
$html.= "\t\t<td>$row[FirstName]</td>\n";
$html.= "\t\t<td>$row[LastName]</td>\n";
$html.= "\t</tr>\n";
}
$html.= "</table>\n";
} else {
$html = "No results\n";
}
Then I only
Print $html;
Quick guide for you who don't know this simple procedure :)
/Mattias aka BoNzO
http://bonzo.sineleven.nu
-----Original Message-----
From: Red [mailto:mightyred34@hotmail.com]
Sent: den 11 augusti 2001 15:38
To: php-db@lists.php.net
Subject: [PHP-DB] Stuck with HTML for MySQL Output
Hi
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, and can't find anything in my
book
which will help me.
Can anyone help please?
Secondly, how do I get Column titles for my database output? I have
tried
everything and can't work it out. I did put a select x as y from
handicap_results in the sql query, but that still only producted the
output
without any column titles.
BTW I am very new to php and sql, have two great book, but I'm having
trouble applying basic php theory which I kind of understand when I
introduce sql outputs!
Here is my script:
<?
$link = mysql_pconnect ("localhost", "xxx", "xxxx") or exit();
mysql_select_db ("aokcc") or exit();
$result = mysql_query ("select * from handicap_results") or exit ();
$num_rows = mysql_num_rows ($result);
print "<b>$num_rows games have been played in the League thus
far.</b><p>";
print "<table border=1 bgcolor=#000099\n";
while ($a_row = mysql_fetch_row ($result))
{
print "<tr>\n";
foreach ($a_row as $field)
print "\t<td>$field</td>\n";
print "<tr>\n";
}
print "</table>\n";
?>
Thanks in anticipation
Regards
Sara
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net