Re: [PHP] MySQL fetch data
On Thursday, June 27, 2002, at 04:20 AM, Jefferson Cowart wrote: > Is there any way to return all the rows returned by a mysql query with > one command. Currently I have to run through a for or while loop the > same number of times as there are rows and take that row and copy it to > an array. I end up with an array of arrays but it seems like it would be > a common enough problem that the function would already exist. You will probably always need to use a looping construct to grab your data (otherwise how will you assign each value to a variable?). But you may find it easier to use mysql_fetch_object(). http://www.php.net/manual/en/function.mysql-fetch-object.php Or maybe not. It's a matter of preference and performance (I think the object version is a bit more expensive). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL fetch data
Jefferson, I am wondering why you would want to do this. If you get the sql statement to order the rows the way you need to use them then there should not be a need to refer back to earlier rows. I sometimes need to know if one field has the same value as in the previous record, so I keep its value in a simple variable so I know if, for example, it is for the same customer or not. I have never found it necessary to refer back an arbitary number of rows, so hence the question. I wonder if you are trying to do too much in a single sql statement? Regards Chris Jefferson Cowart wrote: >Is there any way to return all the rows returned by a mysql query with >one command. Currently I have to run through a for or while loop the >same number of times as there are rows and take that row and copy it to >an array. I end up with an array of arrays but it seems like it would be >a common enough problem that the function would already exist. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL fetch data
> Is there any way to return all the rows returned by a mysql query with > one command. Currently I have to run through a for or while loop the > same number of times as there are rows and take that row and copy it to > an array. I end up with an array of arrays but it seems like it would be > a common enough problem that the function would already exist. No. Write your own wrapper function for MySQL_query() that does it for you...put it in a classuse it. Some abstraction layers that are out there may provide functions that do this for you, though. I generally avoid doing such things if I have to, that way I'm not wasting a bunch of memory in PHP by creating these huge arrays... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL fetch data
On Thursday 27 June 2002 16:20, Jefferson Cowart wrote: > Is there any way to return all the rows returned by a mysql query with > one command. I don't think there is a built-in command to do so. > Currently I have to run through a for or while loop the > same number of times as there are rows and take that row and copy it to > an array. I end up with an array of arrays No need to use a for loop, I prefer to use a while loop. > but it seems like it would be > a common enough problem that the function would already exist. Once you have the code working just wrap it up in a function or a class and away you go. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* My pants just went to high school in the Carlsbad Caverns!!! */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php