are there 开发者_运维问答any way to duplicate the resources produced by functions such as mysql_query?
it may sound dumb but i wanted to reuse such resources so that i won't retype the mysql_query() again and again just to use have a resource..like for example
$rsrc = mysql_query('SELECT * FROM `table` LIMIT 0,1');
$rows = mysql_fetch_array($rsrc);
print_r($rows);
when you fetch a resource, it's value will disappear (that's what i think) what i wanted to do is to reUse it again.i even tried..
$rsrc = mysql_query('SELECT * FROM `table` LIMIT 0,1');
$rsrc_copy = $rsrc;
when you fetch a resource, it's value will disappear (that's what i think) what i wanted to do is to reUse it again.i even tried..
What you are experiencing is not the value disappearing, but the result's internal data pointer moving one row ahead.
It is theoretically possible to move the internal data pointer around using mysql_data_seek()
, but it is rarely practical to do so. I've never seen this used in a real world application. Rather re-use the result you fetched, e.g. by storing the rows in an array.
You don't need to reuse the resource. You can reuse the rows.
Put the result in an array and use it as many times as you like.
$results = array();
$qry = mysql_query("SELECT * from ...");
while($row = mysql_fetch_array($qry)){
$results[] = $row;
}
// use the $results array
精彩评论