I am sending a variable with multiple values like this:
JQUERY:
$(".indexMain").load('indexMain.php?color=' + colors.join("+"), function()
–>
indexMain.php?colors=blue+red+brown
I want to _GET those values and then use them in a while loop to put them into a SQL query like this one:
$items = $con -> prepare("SELECT * FROM item_descr WHERE color_base1 = :colorbase1");
$items -> bindValue(":colorbase1", $color);
Thanks!
EDIT: here is my current code but it is not working, it just shows the items corresponding to the 1st color.
foreach (explode(' ', $_GET['color']) as $color)
{
$items = $con -> prepare("SELECT * FROM item_descr WHERE color_base1 = :colorbase1");
$items -> bindValue(":colorbase1", $color);
}
should be
which is equivalent to
This creates an array accessible with
$_GET['colors']. After that use this PHP:If you don’t want to change the query string, you can do this alternatively:
Note that the only change is in the first line and we are splitting the string by spaces (because “+” gets converted to a space character).
Also note that both examples assume that
$_GET['colors']is defined. You can useisset()to check if it is defined.