Hi guys i have been trying to rap my head around this for some time now. What I'm trying to achieve is get some data from my database, store it in a variable and compare it to a value that is stored in my array.
Problem is it keeps returning the wrong output. From the SQL
query below, the mysql_result $total_cat
returns a value of 16
. Once this value is stored, the code is meant to output echo "this value is in the array";
but its not working.
Where am i going wrong?
This is my Code
Create an array to store my values in
$lunchbox = array(12,13,14,16,20,24,33,32);
Set up my SQL database query
$query = mysql_query("SELECT * FROM table WHERE id = '$the_persons_id'");
Catch my result and store it in a variable
$total_cat = mysql_result($query,0,"category_id");
Clean my result
$total_cat = str_replace("|", " ", $total_cat);
Check if my sql result matches my any of my results stored in my array
if (in_array($total_cat, $lunchbox)) {
echo "this value is in the array";
}else{
echo "this value is not in the array";