<?php // RAY_temp_b0byan.php
error_reporting(E_ALL);
/**
* ?featuresId=18, 2, 50
* SEE http://www.experts-exchange.com/Database/MySQL/Q_28293954.html
*/
// IF THERE IS ANYTHING IN THE REQUEST
if (!empty($_GET['featuresId']))
{
var_dump($_GET);
}
// CREATE THE FORM FOR THE INPUT VALUES
$form = <<<ENDFORM
<form>
<input name="featuresId" />
<input type="submit" />
</form>
ENDFORM;
echo $form;
This code will enable you to see the relationship between the URL variables and the data that arrives in the PHP script via the $_GET array.
<?php // RAY_temp_b0byan.php
error_reporting(E_ALL);
/**
* ?featuresId=18, 2, 50
* SEE http://www.experts-exchange.com/Database/MySQL/Q_28293954.html
*/
// IF THERE IS ANYTHING IN THE REQUEST
if (!empty($_GET['featuresId']))
{
// ACTIVATE THIS LINE TO SEE THE REQUEST VARIABLES
// var_dump($_GET);
// BREAK THE REQUEST VARIABLES INTO AN ARRAY, USING THE COMMA
$arr = explode(',', $_GET['featuresId']);
// ELIMINATE ANYTHING THAT IS NOT A NUMBER
foreach ($arr as $key => $val)
{
$arr[$key] = trim($val);
if (is_numeric($arr[$key])) continue;
unset($arr[$key]);
}
// IF THERE ARE ANY NUMBERS LEFT
if (!empty($arr)) var_dump($arr);
}
// CREATE THE FORM FOR THE INPUT VALUES
$form = <<<ENDFORM
<form>
<input name="featuresId" value="18, 2, 50" />
<input type="submit" />
</form>
ENDFORM;
echo $form;
<?php // RAY_temp_b0byan.php
error_reporting(E_ALL);
/**
* ?featuresId=18, 2, 50
* SEE http://www.experts-exchange.com/Database/MySQL/Q_28293954.html
*/
// IF THERE IS ANYTHING IN THE REQUEST
if (!empty($_GET['featuresId']))
{
// ACTIVATE THIS LINE TO SEE THE REQUEST VARIABLES
// var_dump($_GET);
// BREAK THE REQUEST VARIABLES INTO AN ARRAY, USING THE COMMA
$arr = explode(',', $_GET['featuresId']);
// ELIMINATE ANYTHING THAT IS NOT A NUMBER
foreach ($arr as $key => $val)
{
$arr[$key] = trim($val);
if (is_numeric($arr[$key])) continue;
unset($arr[$key]);
}
// IF THERE ARE ANY NUMBERS LEFT
if (!empty($arr))
{
$where = 'WHERE feature_name = ' . implode(' OR feature_name = ', $arr);
echo $where;
}
}
// CREATE THE FORM FOR THE INPUT VALUES
$form = <<<ENDFORM
<form>
<input name="featuresId" value="18, 2, 50" />
<input type="submit" />
</form>
ENDFORM;
echo $form;
products_id featuresIdOh, NO! Your data base is misdesigned. Please make a Google search for the exact terms "Should I Normalize My Database" and read the very thoughtful discussion on the issue. You should never have more than one atomic value in any column of a data base table. A correct design would link the products_id to the featuresId via a junction table. This would establish the relationship that is inherent in relational data base.
10107 |1|2|3|5|6|22|27|29|53|56|86|96|100| 103|104|11 7|13...
16536 |3|6|9|13|14|21|22|39|40|51|53|56|57 |58|65|66| 136|...
121169 |3|6|7|9|11|12|15|17|18|21|32|34|39| 41|42|50|5 1|56...
<?php // RAY_temp_b0byan.php
error_reporting(E_ALL);
/**
* ?featuresId=18, 2, 50
* SEE http://www.experts-exchange.com/Database/MySQL/Q_28293954.html
*/
// IF THERE IS ANYTHING IN THE REQUEST
if (!empty($_GET['featuresId']))
{
// ACTIVATE THIS LINE TO SEE THE REQUEST VARIABLES
// var_dump($_GET);
// BREAK THE REQUEST VARIABLES INTO AN ARRAY, USING THE COMMA
$arr = explode(',', $_GET['featuresId']);
// ELIMINATE ANYTHING THAT IS NOT A NUMBER
foreach ($arr as $key => $val)
{
$arr[$key] = trim($val);
if (is_numeric($arr[$key])) continue;
unset($arr[$key]);
}
// IF THERE ARE ANY NUMBERS LEFT
if (!empty($arr))
{
$where = "WHERE featuresId LIKE '%|" . implode("|%' OR featuresId LIKE '%|", $arr) . "|%'";
echo $where;
}
}
// CREATE THE FORM FOR THE INPUT VALUES
$form = <<<ENDFORM
<form>
<input name="featuresId" value="18, 2, 50" />
<input type="submit" />
</form>
ENDFORM;
echo $form;
Edited to use "featuresId" instead of "feature_name"
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
I'll look at the problem specifics in a moment. ~Ray