I have this piece of php – mysql code:
When a user tagged in my database as a woman opens the page it queries the database for some data with the number 1012,1013,1014 else only 1012,1013.
// $php_variable=2
$SQL_M = "SELECT @gender:=$php_variable, B.id, B.notes, B.time_logged
FROM database.evs B
INNER JOIN (select @gender:=0) as Something
WHERE
CASE WHEN @gender=2
THEN (B.items IN ('1012', '1013', '1014'))
ELSE (B.items IN ('1012', '1013'))
END
ORDER BY B.time_logged ASC";
$result = mysql_query($SQL_M);
$mycount = mysql_num_rows($result);
if ($mycount > 0) {
while ($mrow = mysql_fetch_array($result))
{
extract($mrow);
echo ">>>>".$id."<br/>"
//Works locally - not on server.
}
}
$php_variable is 2.
It should output items with item id in : 1012,1013,1014
Instead it outputs results for items in 1012,1013.
The strange thing is that I tested this query locally (from php and mysql query alone)
and on the server (Plesk – Mysql) and it runs just fine.
It doesn’t run within the php file in the server -also the ORDER is not functioning properly.
The query that should execute is:
$SQL_M = "SELECT B.id, B.notes, B.time_logged
FROM database.evs B
WHERE B.items IN ('1012', '1013', '1014')
ORDER BY B.time_logged ASC";
Php version: 5.16 (Local and server)
MySQL version: 5.0.77 (local and server)
Thanks in advance for your help.
The way I would do it:
This can be written simpler still, but this is just to show the general idea.