Jump to content

_GET not getting my array


Monkuar

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/256983-_get-not-getting-my-array/
Share on other sites

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 />';
}
}

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!';
}

 

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.