What could be wrong with this a tags link?

right now I have the


[0] => food_types=Array
    [1] => offerings=Array

with the implode formula they have a value of Array not the actual input value.

i just concern of the value it is bring it out, instead shouldn’t be them empty if they are coming as not set input or even display the values if they are set. Above the food_types and offerings variables were set and they came out as Array values.

Well this is the var_dump of the results above I can see the what is printing is the array type instead of the values.

[“frmSearch”]=>
array(2) {
[“food_types”]=>
array(1) {
[0]=>
string(1) “5”
}
[“offerings”]=>
array(1) {
[0]=>
string(1) “5”
}
}

Now the rest of the code you gave me above will be use below as right?

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

i have a question even if this is passing as array value below


[0] => food_types=Array
    [1] => offerings=Array

will the actual value in the var_dump exist yet when $params variable used in as below?

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

thank you.

The whole code would look like.

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

Forget the whole code, get it working one bit at a time. Add a variable/array/whatever to params, print $query, check the link, print_r $params, look for parse errors or warnings, fix, then move to the next one.


[0] => food_types=Array

is that what you expect? if not, why not? and what do you think will happen when you implode that? (hint imploding is concatenating strings).

set in the form to a value=x

Then it is recieved in page2.php like

 $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array();
    $arrOfferings = isset($_POST['frmSearch']['offerings'])?$_POST['frmSearch']['offerings']:array();

therefore

[0] => food_types=Array

food_types should display the value entered in the form not the Array value that it display now.

I might be wrong.

$arrFoodTypes

is set to whatever this evaluates to

isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array();

it should do what you say? then why doesn’t it???


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

// debugging
print_r($params); // is this what you want? no? you only added one line of code, so that line is the one causing problems.
echo $arrFoodTypes;
print_r($arrFoodTypes);
//hmm

What i want is the output of print_r($arrFoodTypes); which is as below when it is set.

ArrayArray
(
[0] => 5
)

The output of print_r($params); will output as in the post above.

Well the problems laids down in there. I don’t see anything wrong since I am assigning the variable ‘food_types=’ a value which is $arrFoodTypes and it is being set. but still it will output [0] => food_types=Array

 $params = array();
$params[] = 'food_types='. $arrFoodTypes; 
$params[] = 'offerings='. $arrOfferings; 

i am not sure what you mean by I just only added one line of code?
I should not use implode function if I am only going to use one line of code? Don’t understand that bit.

If you ignore the arrofferings line, then you just added one line of code to something that was working. So if results aren’t what you expected then you have a very narrow scope to look for problems - specifically with that one line (it might turn out the problem is before that line, but then it is one variable to trace back).

You aren’t assigning $array to a variable when you do this

$string = 'something'.$array;

You are concatenating it to a string. That is echo(ing) it, notice the results above?

You need to learn about types, strings, arrays etc. I’ve tried to show you an approach that can help isolate problems, but you need to be able to solve those problems. Or at least have them simple enough that you can post here with “why does echoing an array not print_r an array” or whatever it is - instead of “my code is broken in multiple places, help!”.

BTW the solution is hopefully obvious from this


$var = array(1, 2, 3);
echo 'string'.$var; echo '<br>';
echo 'string'.implode(',', $var);

Take the time to understand why.

   
$var = array(1, 2, 3);
echo 'string'.$var; echo '<br>';
echo 'string'.implode(',', $var); 

Awww incredible Thank you hash

I can see the problem now echoing without implode just give you the type but implode give you the values of that type…

Now I understand that, I see the comman separating the values.That just one part of what I imaging I am looking for. I think I am not even clear of how to structure what I want in between. the separator, the values, and the assigned variable that will hold the values inside.

For instance:

After a little analysis I have though that instead of putting a 1,2,3 numbers inside of the array function as values then create a dynamical array where the values are going to be generated according to the users input.

 $var = array($_POST['frmSearch']['types'], if !isset($_POST['frmSearch']['offers']){""}else{echo $_POST['frmSearch']['offers]; })
echo 'string'.$var; echo '<br>';
echo 'string='.implode(',', $var); 

The first line is throwing a parse error don’t know why. But that would be the next step to generate those values inside the array dynamically.

I honestly don’t know where to start with tha code sample you’ve provided. There are some fundamental things you need to grasp co.ador.

I’d fix it co.ador, honestly I would, but even now you don’t seem to be grasping any of this.

Take few steps back, start simpler and work up to where you want/need to be, you’ll feel much better for it.

Promise. :wink:

You should consider getting a php book that’s meant for beginners. You have a lot of holes in your knowledge of the basics, and it’s causing you a lot of trouble. You’re trying to run before you can walk.

I find it really difficult to help you.

Let me get a week off and get some knowledge going.

I will do that for some time until I get back on where I am totally lost.

thanks!