I need to change of not my PHP code and I ran into some problem (please notice that I usually code in Java and haven’t develop in PHP for quite few years).
I have the following peace of code:
$sql = "SELECT id_class FROM events e join event_to_class ec on e.id = ec.id_event WHERE e.id = ".$r['id']." and ec.id_evaluator = 8 and (".$stepNumbers.")";
$mirekClassesForEvent = mysql_query($sql) or trigger_error(mysql_error().$sql);
if (!$mirekClassesForEvent) {
echo "Could not successfully run query from DB: " . mysql_error();
exit;
}
$mirekClasses = array();
if (mysql_num_rows($mirekClassesForEvent) > 0 ) {
while($row = mysql_fetch_assoc($mirekClassesForEvent) {
array_push($mirekClasses, $row['id_class'];
}
}
the select statement looks like this:
SELECT id_class FROM events e join event_to_class ec on e.id = ec.id_event WHERE e.id = 1 and ec.id_evaluator = 8 and (e.id_step=4 OR e.id_step=5 OR e.id_step=6)
when I run it in the MySQL DB to runs fine and returns one row of data with
id_class=27
.
However when I run the code above my php script crashes (it doesn’t even show any error messages – even when I try to use mysql_error() function)
From my debuggin it looks like the problem is in the while statement, but I don’t understand what could be the problem.
You are missing a
)at the end of thewhileline, and another on thearray_pushline. If you are seeing no error, you probably have error reporting off. Using an editor with syntax highlighting would help you find this kind of error, as they usually include highlighting of mismatched parentheses.Note that you could simplify your query a little by using
IN:Or
BETWEEN: