Jump to content

looping through array subset


rndilger

Recommended Posts

Hello, I can't seem to figure out how to check a particular subset of array values obtained by using the following statement:

 

while(list($id, $member, $mem_producer, $mem_supplier, $firstname, $lastname) = mysql_fetch_array($resultType))

 

I would like to use a loop to check and see whether $mem_producer, $mem_supplier, and more categories to come are set to 'y' or 'n'. Does the while(list...) statement write the mysql values to an array? If so, what is the name of that array and can I grab a subset of it?

 

Your help is much appreciated.

 

Thanks,

 

Ryan

Link to comment
https://forums.phpfreaks.com/topic/138428-looping-through-array-subset/
Share on other sites

list() doesn't write the values to an array. The result is already returned as an array i.e. mysql_fetch_array();

 

Thanks for the response. If the result is already returned as an array, how can I use that array to create another array?

I want to use something like:

 

$mem_type_check = array_slice(whateverthearrayiscalled,2,count(mem_type)+2);

Ryan

Hello, I can't seem to figure out how to check a particular subset of array values obtained by using the following statement:

 

while(list($id, $member, $mem_producer, $mem_supplier, $firstname, $lastname) = mysql_fetch_array($resultType))

 

I would like to use a loop to check and see whether $mem_producer, $mem_supplier, and more categories to come are set to 'y' or 'n'. Does the while(list...) statement write the mysql values to an array? If so, what is the name of that array and can I grab a subset of it?

 

Your help is much appreciated.

 

Thanks,

 

Ryan

 

This:

 

while($field = mysql_fetch_array($resultType)
{
  $first = $field['firstname'];
}

 

the variable in the brackets [''] is replaced with whatever your database holds

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.