note 34330 added to function.mysql-fetch-assoc

From: Date: Thu, 24 Jul 2003 02:08:45 +0000
Subject: note 34330 added to function.mysql-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-52535@lists.php.net to get a copy of this message
<?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?> HEHE ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34330 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34330&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34330&report=yes

« previous php.notes (#52535) next »