note 108969 added to function.mysql-fetch-array

From: Date: Fri, 08 Jun 2012 16:51:49 +0000
Subject: note 108969 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-188469@lists.php.net to get a copy of this message
Very useful for example. Database.class.php <?php /** *--------------------------------------------------------------- * RESULT ARRAY *--------------------------------------------------------------- * * This function returns the query result as a pure array, * or an empty array when no result is produced. * Typically you'll use this in a foreach for looping. * */ public function result_array($result = '', $type = 'MYSQL_BOTH') { $this->data = array(); if ( $type == 'MYSQL_BOTH') { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { $this->data[] = $row; } } return $this->data; } ?> How to use this method. User.class.php <?php $db = new Database; $query = $db->query('SELECT * FROM users'); // Fetch all users foreach($db->result($query) as $user) { echo $user['id']; echo $user['username']; } ?> ---- Server IP: 80.67.0.53 Probable Submitter: 93.87.122.156 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit -- https://master.php.net/note/edit/108969 Del: integrated -- https://master.php.net/note/delete/108969/integrated Del: useless -- https://master.php.net/note/delete/108969/useless Del: bad code -- https://master.php.net/note/delete/108969/bad+code Del: spam -- https://master.php.net/note/delete/108969/spam Del: non-english -- https://master.php.net/note/delete/108969/non-english Del: in docs -- https://master.php.net/note/delete/108969/in+docs Del: other reasons-- https://master.php.net/note/delete/108969 Reject -- https://master.php.net/note/reject/108969 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188469) next »