balorok Posted August 10, 2010 Share Posted August 10, 2010 Okay, So I'm trying to write a query that will update a certain value in my database, but I want it to update only when 3 conditions are met. Basically, I want to update a column of ints in my DB (mysql) from 0 to a 1, if these criteria are met. 0 and 1 are the only values that are valid in this particular column. dbquery("UPDATE times SET approval = '1' WHERE id = '$id' AND time <= '$currentTime' AND project = '$project'"); that is my query. Now, I'm not even sure if THIS part works. It is however, slightly more complicated in that this query is actually embedded in a foreach loop: $result = $_REQUEST["projects"]; $delimiter - ","; $projectArray = explode($delimiter, $result); foreach($projectArray as $project){ dbquery("UPDATE times SET approval = '1' WHERE id = '$id' AND time <= '$currentTime' AND project = '$project'"); } If you can make any sense of that, and if you can point out any glaringly obvious mistakes here, I would appreciate it. If you need any other information let me know. Thank you all for your help. Quote Link to comment Share on other sites More sharing options...
sinista Posted August 10, 2010 Share Posted August 10, 2010 this line is wrong <?php $delimiter - ","; ?> should be <?php $delimiter = ","; ?> Quote Link to comment Share on other sites More sharing options...
balorok Posted August 10, 2010 Author Share Posted August 10, 2010 Actually, that was just a lost in translation typo... must have changed the = to a - while I was copying it. So, that wasn't the error, still won't update my DB correctly. If I remove the last AND condition, it'll work, but it's updating more rows than I'd like it to. I'm worried I don't have the right syntax to traverse my array and use each element in a query. Quote Link to comment Share on other sites More sharing options...
sinista Posted August 10, 2010 Share Posted August 10, 2010 foreach($projectArray as $project){ $sql="the query you wrote" echo "<p>".nl2br($sql)."</p>"; $result = mysql_query($sql)); } so you have you loop, each itteration will echo the sql so you can check for errors Quote Link to comment Share on other sites More sharing options...
balorok Posted August 10, 2010 Author Share Posted August 10, 2010 Hey, thanks for that. My query is sound, and it works. I had an error in my html call to a javascript that would execute the query located in the other php file. get this: <input type ="hidden" name="projects" valueS="<?php echo $array; ?>"> should have been <input type ="hidden" name="projects" value="<?php echo $array; ?>"> without the damned S. I'm sorry for wasting ya'lls time with what turned out to be my muddled, sleep deprived brain missing something simple. I do appreciate your timely responses however, and your code snippet actually helped me identify that the problem was not with my query, but somewhere else, which let me track this down. Once again, many, many thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.