0

i have this query in link 10_11&9_12&9_14

i need to create array for db to look like this

[0] => 'and value in (11)'
[1] => 'and value in (12,14)'

so i need for every value that is same until _ (in this example 10_ and 9_) to put values after _

this is my code so far:

$test = $_GET['value'];
    foreach($test as $atr_val)
        {
            list($attribute, $value) = explode("_", $atr_val);
            $selected_attributes[] = $attribute;
            $selected_values[] = $value;

        }

i have now values before _ and after, but i don't know what to do after that

3
  • I don't think $_GET is a function :) You probably want to change () -> [] Commented May 9, 2015 at 11:47
  • Please also add how your end results should look like Commented May 9, 2015 at 11:49
  • you have that, i already wrote it [0] => and value in (11) [1] => and value in (12,14) Commented May 9, 2015 at 11:50

1 Answer 1

1

Let your query string looks like www.example.com?file.php?10_11&9_12&9_14

Then use this code. Collect them into array and use implode to output:

$test = $_SERVER["QUERY_STRING"];
$test = explode('&', $test);
foreach($test as $atr_val)
   {
   list($attribute, $value) = explode("_", $atr_val);
   $selected_values[$attribute][] = $value;
   }
 foreach($selected_values as $value) 
   echo "and value in (".implode(',', $value).")".'<br>';

output:

and value in (11)
and value in (12,14)
Sign up to request clarification or add additional context in comments.

6 Comments

i tried this, but i have this error Fatal error: [] operator not supported for strings. maybe because i use php 5.3?
Get gives you array so for debug use $test = array('10_11','9_12','9_14');
ok, i am getting first this this empty results, how to get rid of them? and value in () and value in () and value in (11) and value in (12,14)
now i get empty results and value in () and value in () and value in (). am I doing something wrong?
Look my answer. I've changed beginning
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.