note 100702 added to function.mysql-fetch-array
| From: | SiroosSheikhi at osu1 dot php dot net | Date: | Mon, 01 Nov 2010 10:27:15 +0000 |
| Subject: | note 100702 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173636@lists.php.net to get a copy of this message | ||
we can use our query result like as dataset in .net & mssql
for this we should write a function to convert mysql query result to an array like as table !
i wrote a simple & short function for this :
function result2dataset($query)
{
$result=mysql_query($query,$mysqlconnection);
$r=array();
while($row=mysql_fetch_array($result,MYSQLI_BOTH)) //you can use MYSQL_NUM , or MYSQL_ASSOC as
you want
$r[]=$row;
return $r;
}
//now use function
$q="select f1,f2,f3 from table";
$dataset=result2dataset($q);
foreach($dataset as $row)
{
echo $row[0].$row['f2'].$row[2]; //call by filed name or number is dependent on
MYSQL_BOTH,MYSQL_NUM or MYSQL_ASSOC
}
----
Server IP: 79.132.192.3
Probable Submitter: 79.175.191.83
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- https://master.php.net/note/edit/100702
Del: integrated -- https://master.php.net/note/delete/100702/integrated
Del: useless -- https://master.php.net/note/delete/100702/useless
Del: bad code -- https://master.php.net/note/delete/100702/bad+code
Del: spam -- https://master.php.net/note/delete/100702/spam
Del: non-english -- https://master.php.net/note/delete/100702/non-english
Del: in docs -- https://master.php.net/note/delete/100702/in+docs
Del: other reasons-- https://master.php.net/note/delete/100702
Reject -- https://master.php.net/note/reject/100702
Search -- https://master.php.net/manage/user-notes.php