Jump to content

for loop inside another for loop


garry27

Recommended Posts

i have this code:

[code]for ( $i = 0; $i <10; $i++ )
$chkbox_arr[$i]; 
    for ( $ii = 0; $ii <10; $ii++ )
      $sql_arr[$ii] = ' AND '.$chkbox_arr[$i]."='y' "; [/code]

what I'm trying to do is create a new array which adds ' AND '.$chkbox_arr[$i]."='y' "; for each value in $chkbox_array. but all i get is:

AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y'

pleasecan someone show me how to fix this.

thanks in advance

Link to comment
Share on other sites

ok. i'm trying to adjust each value in the $chkbox_arr array so that it adds

" AND *followed by the value* ='y' "

this array im trying to store in $sql_ arr

currently each value in  $chkbox_arr is a string word which relate to a column on a mysql table

i will then use the implode function to add the new values together in a single string so i can use in a where clasuse in mysql.

the problem now is that the only result i'm getting is:

AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y' AND ='y'

..regardless of what's in the $chkbox_arr array



Link to comment
Share on other sites

i'm trying to do something like this but using for so it keeps track of the index:

[code]foreach ($chkbox_arr as &$value)
$value = "AND $chkbox_arr 'y'"; [/code]

if i use the code above all i get is AND Array 'y' for each value that is returned. instead of the actual value contained in the array it just says Array. i has a similar problem with this when i tried to create $ckbox_arr array using a a foreach loop.  ???
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.