note 45501 added to function.mysql-fetch-object

From: Date: Thu, 09 Sep 2004 09:06:47 +0000
Subject: note 45501 added to function.mysql-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-76283@lists.php.net to get a copy of this message
Here is a good example to begin with mysql and php have fun |sa||as|=|sa||as@sackratte.net|=|http://www.sackratte.net| <?PHP ### connect to database $db = mysql_connect("www.sackratte.net", "user", "pass123") or die ("<br><i>ERROR</i> in connect function (" . mysql_errno() . ": " . mysql_error() . ")\n"); ### select database mysql_select_db("friends", $db) or die ("<br><i>ERROR</i> in connect function (" . mysql_errno() . ": " . mysql_error() . ")\n"); ### request information from database $result = mysql_query("SELECT fname, sname, phone, cellphone, mail FROM addresses ORDER BY sname", $db); if (!$result) { echo "Error in mysql_query (" . mysql_errno() . ": " . mysql_error() . ")\n"; exit; } ### display number of friends in database $num_entries = mysql_num_rows($result); echo $num_entries . " friends in database"; ### show result echo '<table>'; # this is the tables header , background color is grey echo '<tr bgcolor="#cccccc"><td>Name</td><td>First Name</td><td>Phone</td><td>Cellphone</td><td>Mail</td></tr>'; while ($friend = mysql_fetch_object($result)) { echo '<tr><td>' . $friend->sname . '</td><td>' . $friend->fname . '</td><td>' . $friend->phone. '</td><td>' . $friend->cellphone. '</td><td>' . $friend->mail . '</td></tr>'; } echo '</table>'; ### close database connection mysql_close($db); ?> ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-object.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45501 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45501&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45501&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76283) next »