[PHP-DB] Re: how to reuse DB results
Sorry for mystakes, (shame on me, i said i was new) using Object array, here is a working version (tested) with use of array. Bye $recordset=mysql_query('SELECT * FROM my_tabella'); // or whatever query is /* define an array with 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('key01','key02','key03'); /* u can use $_REQUEST variables instead of fixed values*/ $i=0; while($record=mysql_fetch_array($recordset, MYSQL_ASSOC)) { foreach ($record as $k=$val) if ($k==$my_key[$i]) { // echo the top of the page echo p$k :$val/p; /* if u need a top_array to store result shown on top of the page, comment this line only $top_array[$i]=$val; // loose the matching key-field!! */ $i++; } } //reset the resource mysql_data_seek($recordset,0); // some middle-page code here echo 'pthis is the bottom page and displays the whole result/p'; while ($record=mysql_fetch_array($recordset, MYSQL_ASSOC)) foreach ($record as $k=$val) echo p$k : $val/p; // make your choice for html code mysql_free_result($recordset); // Bye Aaron Wolski [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: how to reuse DB results
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 'pthis 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 [EMAIL PROTECTED] ha scritto nel messaggio news:[EMAIL PROTECTED] 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php