Monkuar Posted February 13, 2012 Share Posted February 13, 2012 My code to Generate my data dynamically: $DB->query("SELECT g_title,g_id from ibf_groups where g_title NOT IN ('Validating','Guests') order by rank ASC"); while ($group = $DB->fetch_row()) { $data[$group['g_id']] = $group['g_title']; } $letters2 = $data; //var_dump($data); $group=(empty($group))?'':$group; $group.='<center><div class=pages>Group: '; foreach ($letters2 as $letter2 => $ids) { $group .= '<a href="?a=(^_-)&filter='.$letter2.'">'; if (isset($_GET['filter']) && $_GET['filter'] == $letter2){ $group .="<b>{$data[$letter2]}</b>"; }else{ $group .="{$data[$letter2]}"; } $group .= '</a>'; if ($data[$letter2]!="Loser"){ $group .=" • "; } } MY code so I can use to filter the groups with my database if ( isset( $_GET['filter'] ) AND in_array($_GET['filter'], $letters2 ) ){ echo "hey"; exit; // CONNECT TO DATABASE AND QUERY $q_extra .= " AND m.mgroup IN($_GET['filter'])"; // DO QUERY AND CHURN OUT RESULTS } something is wrong, because in my original foreach I am using the => And it's not reading through my $letters2 correctly? (I will use mysql_escape once done) but I cannot even bring up the echo "hey" on a &filter=XXX I am stumped Quote Link to comment https://forums.phpfreaks.com/topic/256983-_get-not-getting-my-array/ Share on other sites More sharing options...
MMDE Posted February 13, 2012 Share Posted February 13, 2012 Try to print/echo wherever you wonder if the data has passed through or not. For example before your code so I can use to filter the groups with my database: print_r($letters2); And btw, it is pointless to check if the get data is set when you're using it at the same time: if ( isset( $_GET['filter'] ) AND in_array($_GET['filter'], $letters2 ) ){ } You should try: if( isset($_GET['filter']) ){ echo 'GET[\'filter\'] = ' . $_GET['filter'] . '<br />'; if( in_array($_GET['filter'], $letters2) ){ echo $_GET['filter'] . ' is in the $letters2 array!<br />'; } } Quote Link to comment https://forums.phpfreaks.com/topic/256983-_get-not-getting-my-array/#findComment-1317492 Share on other sites More sharing options...
kicken Posted February 13, 2012 Share Posted February 13, 2012 And btw, it is pointless to check if the get data is set when you're using it at the same time: You can do that, and it will not cause any error. PHP will "short-circuit" conditionals so that as soon as it determines the condition cannot be satisfied it will stop executing it. In the given example if isset($_GET['filter']) is false due to it not existing, php will never execute the in_array portion and no undefined index error will be generated. @monkuar If I understand your code correctly, you want to check that the value in $_GET['filter'] exists as a key in your $letters2 array. in_array only searches the values of the array, not the keys. To check for the key you can use either array_key_exists or just isset() on that key, eg: if (isset($_GET['filter']) && isset($letters2[$_GET['filter']])){ echo 'Hey!'; } Quote Link to comment https://forums.phpfreaks.com/topic/256983-_get-not-getting-my-array/#findComment-1317611 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.