ok, I have not done sql in a while and I am desperately trying to get this query to work. I have read other solutions, but they require such a complex query, I am convinced that there is an easier way to do this......
THE SET-UP:
I have a guestbook application we are developing - the users enter a guestbook entry. The entries are automatically set to have their status set to "0" - which means not approved for display.
We have everything working, and now we are working on the admin part - approving and disapproving the entries. An admin sees a form with each entry listed on a seperate row of a table and a checkbox for "Mark as Read", "Approve", and "Deny". This part works as well.
PROBLEM:
The UPDATE query is not doing anything. When we check 1 box, it is ok, but with several boxes, it is not doing anything. I go into phpmyadmin and try the query in the SQL box, and it does not do anything there either. - CONCLUSION - it is my update statement with several rows that is not doing anything.
THE CODE
IF(count($denyArray) >= 1)
{
//denyArray is passed to this function - it contains the id key of each item in the
//database that has been checked as "denied".
//Make Denial Query
$denialQuery = "UPDATE $table SET status = '0' WHERE";
foreach ($denyArray as $check)
{
//$table is passed to this function as well, it is the name of table (duh LOL)
$denialQuery .= " $table.id = '$check' AND";
}//end foreach
//get rid of last AND
$denialQuery = substr($denialQuery, 0, -3);
PRINT("<br><br>Denail Query = <br>$denialQuery<br>");
return mysql_query($denialQuery);
}//end if
THE RESULTING QUERY:
When we test it by selecting the first 6 entries, this is the resulting query:
UPDATE guestbook SET status = '0' WHERE guestbook.id = '1' AND guestbook.id = '2' AND guestbook.id = '3' AND guestbook.id = '4' AND guestbook.id = '5' AND guestbook.id = '6'