SephirGaine Posted August 9, 2006 Share Posted August 9, 2006 Whooptie. I'm back (unfortunately, again), however this time my question's a lot different. I'll start off by posting my code..[code]<?php $query1 = "UPDATE `WOR` SET Invoice=Yes where work_order_num='$ordernum' where Invoice=No"; $query2 = "UPDATE `WOR` SET Invoice=No where work_order_num='$ordernum' where Invoice=Yes";?><?php if (mysql_query($query1) or die(mysql_error()) else { mysql_query($query2) or die(mysql_error(); }?>[/code]What I want to do is to basically switch the "Invoice" section of an entry to Yes or No, much like a toggle. However, I'm running into a few problems when I try to run the script. Unfortunately I'm not sure where I've gone wrong. I can see it being either I can't use 2 "where" statements in a single query, or it's in my else statement (syntax error somewhere). Any help would be appreciated, and if there's a simpler way for me to do this, I'm all ears. This is just what I came up with off the top of my amateur head. Thanks! Link to comment https://forums.phpfreaks.com/topic/16984-updating-a-table-using-2-filters/ Share on other sites More sharing options...
ToonMariner Posted August 9, 2006 Share Posted August 9, 2006 <?php $query = "UPDATE `WOR` SET Invoice=Yes where work_order_num='$ordernum' AND Invoice=No;"; $query .= "UPDATE `WOR` SET Invoice=No where work_order_num='$ordernum' AND Invoice=Yes;";$qry = mysql_query($query);if 9mysql_affected_rows() == 0){ // output some error warninh}?> Link to comment https://forums.phpfreaks.com/topic/16984-updating-a-table-using-2-filters/#findComment-71597 Share on other sites More sharing options...
SephirGaine Posted August 9, 2006 Author Share Posted August 9, 2006 Hm.. getting a syntax error when I try it. I get the idea though, so thanks! Changed what you gave me just a bit, came up with this..[code]<?php $query = "UPDATE `WOR` SET Invoice=Yes where work_order_num='$ordernum' AND Invoice=No"; $query .= "UPDATE `WOR` SET Invoice=No where work_order_num='$ordernum' AND Invoice=Yes"; ?> <?phpmysql_query($query) or die(mysql_error());if (mysql_affected_rows() == 0){ echo("An error has occured.");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/16984-updating-a-table-using-2-filters/#findComment-71600 Share on other sites More sharing options...
SephirGaine Posted August 9, 2006 Author Share Posted August 9, 2006 Hate to be a pain, but bumpin' 'dis. Still having a bit of trouble.. see one post up. ??? Link to comment https://forums.phpfreaks.com/topic/16984-updating-a-table-using-2-filters/#findComment-71938 Share on other sites More sharing options...
sasa Posted August 9, 2006 Share Posted August 9, 2006 "UPDATE `WOR` SET `Invoice`=(SELECT IF(`Invoice`='Yes','No',Yes')) where work_order_num='$ordernum'" Link to comment https://forums.phpfreaks.com/topic/16984-updating-a-table-using-2-filters/#findComment-71956 Share on other sites More sharing options...
SephirGaine Posted August 9, 2006 Author Share Posted August 9, 2006 Most unfortunately..[quote]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT IF(Invoice='Yes','No','Yes')) where work_order_num='2''[/quote]This is what I've got..[code]<?php $query = "UPDATE `WOR` SET Invoice=(SELECT IF(Invoice='Yes','No','Yes')) where work_order_num='$ordernum'" ?> <?phpmysql_query($query) or die(mysql_error());?>[/code] Link to comment https://forums.phpfreaks.com/topic/16984-updating-a-table-using-2-filters/#findComment-72083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.