I am trying to get values from an array that is stored in a column in my database. I have this code so far:
<?php $disciplines = (json_decode($traveler['disciplines'])); ?>
<?php $disciplinename = implode(' OR id = ',$disciplines); ?>
<?php $name = "SELECT * from the_discipline WHERE (id = 86 OR id = 118)";
$dname = $obj->queryResult($name);
Everything works fine up to a point. I am able to get the array that looks like this in the database "["86", "118"]" and print it out to look like this "86 OR id = 118" (that is the $disciplinename variable) I am then trying to put it in an SQL statement that looks like this "SELECT * from the_discipline WHERE (id = ".$disciplinename.")";. When I do that statement my page won't load and if I type out the statement without the variable like so "SELECT * from the_discipline WHERE (id = "86 OR id = 118")"; it works fine. I have rearranged things and tried many variations of the above code but I can't get anything to work properly. Is there something I'm missing or don't know about using implode() with SQL? Any input or pointers would be much appreaciated.
EDIT*
I have also tried this as suggested below:
<?php $disciplines = (json_decode($traveler['disciplines'])); ?>
<?php $disciplinename = implode(', ',$disciplines); ?>
<?php $name = "SELECT * from the_discipline WHERE id IN (".$disciplinename.")";
$dname = $obj->queryResult($name);
?>
.. WHERE id IN (..comma-separated-list..);implodetoo?