What could be wrong with this a tags link?

let me do the var dump with $_GET

it means the first time it passes as POST because the form method is POST then in the indexpagination it becomes $_GET and to get it in the pagination links to work then I have to send it as $_GET. the var_dump($_GET) will show results depending on the users input. But then when I click in the pagination links it will throgh some error saying undefined indexes because they are in POST again. So what I have use is $_REQUEST which serves for both $_GET and POST but then $_REQUEST won’t work properly for Arrays.

it will still throw the undefined error just for the array values even when I use $_REQUEST. Does the Global variable $_REQUEST has any problem with arrays?

<a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&name=". $_REQUEST['name']. '&zipcode=' . $_REQUEST['zipcode'] .'&state=' . $_REQUEST['state'] . '&food_types= ' . $_REQUEST['frmSearch']['food_types'][0]. '&offerings=' . $_REQUEST['frmSearch']['offerings'][0]."'><</a> 

Look the index name, zipcode and state will work ok with $_REQUEST but then offerings and foodtypes which are array types will fail and throw a undefined index even when I use $_REQUEST.

Notice: Undefined index: frmSearch in C:\wamp\www
yhungry\indexpagination.php on line 512

Notice: Undefined index: frmSearch in C:\wamp\www
yhungry\indexpagination.php on line 512
<<
Notice: Undefined index: frmSearch in C:\wamp\www
yhungry\indexpagination.php on line 518

Notice: Undefined index: frmSearch in C:\wamp\www
yhungry\indexpagination.php on line 518
< 1 [2]

that’s very interesting.

Do a print_r of $_REQUEST and see what it contains.

below is an print_r and a var_dump of $_REQUEST after paginating when coming from the form then the only difference is the submit index that will show up.

Array
(
[currentpage] => 2
[name] =>
[zipcode] => 10468
[state] =>
[food_types] => Array
[offerings] =>

)
array(7) {
[“currentpage”]=>
string(1) “2”
[“name”]=>
string(0) “”
[“zipcode”]=>
string(5) “10468”
[“state”]=>
string(0) “”
[“food_types”]=>
string(6) " Array"
[“offerings”]=>
string(0) “”

}

It looks like there’s no such thing as a $_REQUEST[‘frmSearch’], so maybe you should try

$_REQUEST[‘food_types’][0]

and

$_REQUEST[‘offerings’][0]

instead.
Although ‘offerings’ doesn’t seem to be an array, it’s empty.

look at it now it is an array. It just going crazy and heated right now.

I have taken out the [“frmsearch”] but still it will display some undifined messages!

that’s the var_dump below.

array(6) {
[“name”]=>
string(0) “”
[“zipcode”]=>
string(5) “10468”
[“state”]=>
string(0) “”
[“frmSearch”]=>
array(2) {
[“food_types”]=>
array(1) {
[0]=>
string(1) “5”
}
[“offerings”]=>
array(1) {
[0]=>
string(1) “5”
}
}

But now ‘frmSearch’ is there.
It seems that you send different things in different occasions. You have two choices:

  1. always send the same variables
  2. manage the different scenarios

The thing is that offering will only appear if it is set onlye as a difference from the other input of the form.

offering is a checkbox input field.

You mean two choices with this kind of form?

how would be always sending the same variable?

It sound like the second option if what I am loooking for manage the different scenarios where user will be free to enter what they want. The form works alright the issues comes when passing the variables of the form through the pagination script.

I have tried to implode the two array inside the link like

<?php 
      echo  "<a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&name=". $_REQUEST['name']. '&zipcode=' . $_REQUEST['zipcode'] .'&state=' . $_REQUEST['state'] . 
	  implode('&food_types= ','&offering' array($_REQUEST['frmSearch']['food_types'] $_REQUEST['frmSearch']['offerings'])"'><</a> ";
?>

Is this imploding fucntion done corretly?

the above is a pagination link that will retrieve five indexes and two of them are arrays. as I said I have put the two array inside the implode function and the rest outside.

Help!

Are you seriously asking that? I mean did you even try? or just start typing here instead of your code editor?

I tried the follows but it’s not activating the >> as a link. I think somewhere in between <a the script inside the <a open and the symbol > then it get lost the effect of activating the link.

echo "<a href='{$_SERVER['PHP_SELF']}?currentpage={$nextpage}&name={$_POST['name']}&zipcode={$_POST['zipcode']}&state={$_POST['state']}&food_types=".(is_array($_REQUEST['frmSearch']['food_types'])) ? implode(",", $_REQUEST['frmSearch']['food_types']) : ""."&offerings=".(is_array($_REQUEST['frmSearch']['offerings'])) ? implode(",", $_REQUEST['frmSearch']['offerings']) : ""."'>>></a>"; 

again the >> is not display as a link rather as a plain text with the script above.

implode(",", $_REQUEST['frmSearch']['food_types']) 

the implode here will separate the variables array and its $_REQUEST value from the other variables, if the test results as true else : false. But some how the link is not being activated and it is not displaying any error it just that the >> won’t link.

> is a special character in html, you need to use > or something else like » might be better

still the problems persists.

This is the output of the pagination even with the symbols you gave me to substitute >

[1] 2 '>»>
Notice: Undefined index: offerings in C:\wamp\www
yhungry\indexpagination.php on line 553
>>

you see >»> it won’t link and if you notice in [1] 2 '>»> the apostrophe ’ is part of the closing in the php script inside the <a> tags won’t will appear as plain text. I don’t see any missing tags or any missing parse characters in there.

Hai!!!

When you have a difficult problem, simplify it. Why don’t you do this one variable at a time and see where the problems are.

Here is a start point:


$params = array();
$query = implode('&', $params);
echo '<a href=".$_SERVER['PHP_SELF'].'?'.$query.'">next</a>';

There is a typo in that, but see how easy it is to spot with syntax highlighting, and a small amount of code.

i have seem the typo thank you. The text next links good.

Now I am trying to fill the array like

$params = array('food_types=' . $_REQUEST['frmSearch']['food_types'] . offerings=' .$_REQUEST['frmSearch']['offerings']);

tried like that didn’t work. Don’t know weather I should include the variable ‘food_types’ and ‘offerings’ inside the array.

or instead assign it in the implode function!

$params = array($_REQUEST['frmSearch']['offerings']);
$query = implode('&offerings=', $params);
echo "<a href=".$_SERVER['PHP_SELF'].'?'.$query.">next</a>";

$params = array();
$params[] = 'something='.$somevar; 
$params[] = 'anotherthing='.implode(',', $anothervar);

You can


echo '<pre>'; print_r($params); echo'<pre>';

to see a nicely formatted array of what’s in params before you use it