Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

tep_db_fetch_array() only returns ONE ROW


Aalst

Recommended Posts

Posted

I want to run a SQL query that returns several rows. When I use tep_db_fetch_array() it only returns the first row of the query. How can I get a 2D Array of the rows? That way I can increment the rows and access the data all in one array. Is there a TEP function that does this, or even a MYSQL function. I checked php.net and I couldn't figure out if any of the functions return more than one row, preferably in a 2D array.

 

Thanks...

 

-Aalst

Posted

Forgot to say, that I know if I call tep_db_fetch_array with the same query that each will return the next row. Was hoping there was a single function call to get a 2D Array. Thought that would save some time :)...

Posted

$query=tep_db_query("YOUR SQL QUERY HERE");

while ($new_values = tep_db_fetch_array($query)){

<DO SOMETHING WITH THIS ROW>;

}

-------------------------------------------------------------------------------------------------------------------------

NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit.

If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help.

Posted

Thanks Chris, but as I stated, I know how to do that, and as a matter of fact that is exactly what I am doing. I was just wondering if there was a way to get a 2D Array without having to create it myself using this method. :)

Posted

That is a 2D array.

 

Do you mean a hash, or associative array?

-------------------------------------------------------------------------------------------------------------------------

NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit.

If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help.

Posted

Well, it occurs to me that you'd need either an array of arrays, or an array of character strings, with each of the elemets acutally being a comma seperated string of values.

-------------------------------------------------------------------------------------------------------------------------

NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit.

If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help.

Posted

A 2D Array is an Array of Arrays.

 

Example:

$array[ ][ ]

 

A multi-diminsional array is an Array of n number of other arrays. 2D is Array of Arrays, 3D is Array of Arrays of Arrays, etc etc...

Posted

No, you can't get all the results at once. You have to get them row by row. If you want them in an array of results you will have to put them there manually. You might be able to use a short hand like

$results = array();
while ($results[] = tep_db_fetch_array($query));

but I have never tried it.

 

Hth,

Matt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...