Jump to content

Updating a table, using 2 filters


SephirGaine

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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";
  ?>
  <?php
mysql_query($query) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
echo("An error has occured.");
}
?>[/code]
Link to comment
Share on other sites

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'"
  ?>
  <?php
mysql_query($query) or die(mysql_error());
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.