note 69498 added to function.mysql-fetch-row
| From: | pbrisson at gmail dot com | Date: | Thu, 07 Sep 2006 19:43:12 +0000 |
| Subject: | note 69498 added to function.mysql-fetch-row | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116876@lists.php.net to get a copy of this message | ||
(Thanks to Victor Ocampo for his comment quoting me. Here's the original comment, for those who
want the function...)
I'm used to dataset objects, so I've made this function to parse mysql results, instead of
using mysql_fetch_row... It may not be fast, but since I'm often using the same data all over
my scripts, I just need to run it once.
<?
function dataset($sql)
{
global $SQL_HOST, $SQL_USER, $SQL_PASS, $SQL_DB;
@$link = mysql_connect($SQL_HOST, $SQL_USER, $SQL_PASS);
if (!$link)
{
die("Database error: " . mysql_error() . "<br><br>Please
contact admin.");
}
mysql_select_db($SQL_DB);
$result = mysql_query($sql, $link);
for($i=0;$i<mysql_num_rows($result);$i++)
{
$datapool[$i] = mysql_fetch_row($result);
}
mysql_close($link);
return $datapool;
}
?>
So I can call it this way:
<?
$dataset = dataset("SELECT * FROM employees");
?>
And to retrieve, let's say the 3rd field of the 2nd row, I use:
<?
$value = $dataset[1][2];
?>
Pierre-Yves Lapointe Brisson
----
Server IP: 66.207.199.35
Probable Submitter: 24.37.47.94
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-row.php
Edit -- https://master.php.net/note/edit/69498
Del: integrated -- https://master.php.net/note/delete/69498/integrated
Del: useless -- https://master.php.net/note/delete/69498/useless
Del: bad code -- https://master.php.net/note/delete/69498/bad+code
Del: spam -- https://master.php.net/note/delete/69498/spam
Del: non-english -- https://master.php.net/note/delete/69498/non-english
Del: in docs -- https://master.php.net/note/delete/69498/in+docs
Del: other reasons-- https://master.php.net/note/delete/69498
Reject -- https://master.php.net/note/reject/69498
Search -- https://master.php.net/manage/user-notes.php