garry27 Posted October 26, 2006 Share Posted October 26, 2006 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 https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/ Share on other sites More sharing options...
Psycho Posted October 26, 2006 Share Posted October 26, 2006 I think you need to be more specific in what you are trying to accomplish. I've tried deciphering what you may want from your text and your code and don't have a clue. Give an example of the resulting array and values you want and we can help. Link to comment https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/#findComment-115106 Share on other sites More sharing options...
garry27 Posted October 26, 2006 Author Share Posted October 26, 2006 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_ arrcurrently each value in $chkbox_arr is a string word which relate to a column on a mysql tablei 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 https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/#findComment-115113 Share on other sites More sharing options...
Psycho Posted October 27, 2006 Share Posted October 27, 2006 Still not 100% sure, how bout this:[code]foreach ( $chkbox_arr as $KEY => $column ) { $sql_arr[$KEY] = ' AND ' . $COLUMN . "='y' "; }[/code] Link to comment https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/#findComment-115156 Share on other sites More sharing options...
garry27 Posted October 27, 2006 Author Share Posted October 27, 2006 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 https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/#findComment-115167 Share on other sites More sharing options...
garry27 Posted October 27, 2006 Author Share Posted October 27, 2006 i've sorted it now, thanks. it was a lot simpler problem than i thought.[code]sort ($chkbox_arr); $result = count($chkbox_arr); echo $result; for ( $i = 0; $i <$result; $i++ ) $chkbox_arr[$i]="AND $chkbox_arr[$i]='y'";[/code] Link to comment https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/#findComment-115176 Share on other sites More sharing options...
Psycho Posted October 27, 2006 Share Posted October 27, 2006 I thought you might be moking more difficult than it needed to be - I was lost. Here is a simpler method, that doesn't require to to sort first.[code]foreach ( $chkbox_arr as $key => $value ) { $chkbox_arr[$key]="AND $value ='y'";}[/code] Link to comment https://forums.phpfreaks.com/topic/25242-for-loop-inside-another-for-loop/#findComment-115346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.