note 54050 added to ref.mysql
| From: | james at tendirect dot com | Date: | Wed, 22 Jun 2005 04:32:48 +0000 |
| Subject: | note 54050 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90774@lists.php.net to get a copy of this message | ||
<?
/* ---------------------------------------------- */
/* ------------ BEGIN PHP SNIPPET ----------------*/
/* ---------------------------------------------- */
$cfg_hostname = "host"; // database host
$cfg_dbUser = "username"; //database username
$cfg_dbPass = "password"; //database password
$cfg_dbName = "database"; // database name
// connect to the db
if (!mysql_pconnect($cfg_hostname, $cfg_dbUser, $cfg_dbPass))
die('FATAL: cannot connect to mySQL server');
if (!mysql_select_db($cfg_dbName))
die('FATAL: I cant make up my mind!! Cannot select MySQL database');
// state the query
$sql = "select name, address from bar order by name asc";
// check to make sure the query went through okay
if ($get_first_query = mysql_query($sql)) {
$num_items = mysql_num_rows($get_first_query);
// if there were any matching results, continue
if ($num_items > 0 ) {
echo "<table>";
$rowcolor = 0;
while (list($name, $address) = mysql_fetch_row($get_first_query)){
$rowcolor++;
$report_class = ($rowcolor % 2) ? '#DBDBDB' : '#FFFFFF';
echo "<tr>\n";
echo "<td bgcolor=\"".$report_class."\">$name</td>\n";
echo "<td bgcolor=\"".$report_class."\">$address</td>\n";
echo "</tr>\n";
} // endwhile
echo "</table>";
}
} else {
// if the query broke, find out why
echo "Ack. MySQL had a problem!";
echo mysql_error();
}
/* ---------------------------------------------- */
/* ------------ END PHP SNIPPET ----------------*/
/* ---------------------------------------------- */
?>
This code displays a table and it's contents, but how do I edit the contects in a simple raw
code editor.
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54050
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54050&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54050&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54050&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54050&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54050&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54050&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54050&report=yes
Search -- http://master.php.net/manage/user-notes.php