Re: how to reuse DB results
| From: | franciccio | Date: | Thu, 10 Jun 2004 01:19:18 +0000 |
| Subject: | Re: how to reuse DB results | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-34757@lists.php.net to get a copy of this message | ||
Hi here is my logic, i haven't tested but it should work (i hope)!!!
i'm not sure if it works only on php5...!?! Let me know if it is a complete
crap i've just started learning php.
Bye
$recordset=mysql_query($query); // whatever query is
$obj_array=new ArrayObject($recordset);
// get the iterator now
$interator=$obj_array->getIterator();
// you can now easly navigate in the recordset by the iterator
/* define an array with n fields to be shown on top of page. Attention
...values name must be the same of table field names you want to show on top
of the page*/
$my_key = array(0=>'key1',1=> 'key2',....,n-1=>'keyn');
// echo the top of the page
$i=0;
while($iterator->valid())
{
if ($iterator->key()==$my_key[$i] )
{
echo "<p>".$iterator->key()." :
".$iterator->current()."</p>";
/* if u need a top_array to store result shown on top of the page,
uncomment this line only
$top_array[$i]=$iterator->current(); // loose the matching
key<->field!! */
$i++;
$iterator->next();
}
else
$iterator->next();
}
/* to display the whole recordset resulting from the query don't forget
you still have
$recordset free to use with mysql_fetch_array() or other way to display */
echo '<p>this is the bottom page and displays the whole result</p>';
while ($res=mysql_fetch_array($recordset))
for each ($res as $k=>$val)
echo "<p>$k : $val</p>"; // make your choice for html code
"Aaron Wolski" <aaronjw@martekbiz.com> ha scritto nel messaggio
news:032e01c43ea6$f099efd0$6901a8c0@AJW2...
> Hi All,
>
> Got this logic problem I don't know how to solve.
>
> Is there any way I can make a call to the DB for some records.
>
> Display some info from a column or two say at the top of the page and
> then display the full result set in a while() loop?
>
> Right now, I am making two calls to the Db to get the data I need to
> display at the top of the page and then a second query to retrieve the
> full result set.
>
> I'm confused!
>
> Thanks for any help!
>
> Aaron