update row value based on if else condition
In php Page once we click on "Submit" button , in database we are saving order id, its working fine....
Requirement :
If payment is "Cash on delivery" , than i want to save order id in "awb_type : COD" row.... otherwise in "awb_type : PPD" row....
here is full code , track.php : https://pastebin.com/zLjpee7A , call.php : https://pastebin.com/4LkcxTYE
But orders are updating twice in table - one row in PPD & one in COD
Please let me know if you need more information....
Update 2 :
Now i tried below code, but whatever is payment_type , its saving only in awb_type column : PPD rows....
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
$resultc = $db_handle->runSelectQuery($sqlc);
$sqld = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
$resultd = $db_handle->runSelectQuery($sqld);
$payment_type='';
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$awb = $resultc[0]['awb'];
$sqle = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awb."' limit 1";
$resulte = $db_handle->runSelectQuery($sqle);
}
else
{
$awba = $resultd[0]['awb'];
$sqlf = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awba."' limit 1";
$resultf = $db_handle->runSelectQuery($sqlf);
}
php mysql sql if-statement
|
show 9 more comments
In php Page once we click on "Submit" button , in database we are saving order id, its working fine....
Requirement :
If payment is "Cash on delivery" , than i want to save order id in "awb_type : COD" row.... otherwise in "awb_type : PPD" row....
here is full code , track.php : https://pastebin.com/zLjpee7A , call.php : https://pastebin.com/4LkcxTYE
But orders are updating twice in table - one row in PPD & one in COD
Please let me know if you need more information....
Update 2 :
Now i tried below code, but whatever is payment_type , its saving only in awb_type column : PPD rows....
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
$resultc = $db_handle->runSelectQuery($sqlc);
$sqld = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
$resultd = $db_handle->runSelectQuery($sqld);
$payment_type='';
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$awb = $resultc[0]['awb'];
$sqle = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awb."' limit 1";
$resulte = $db_handle->runSelectQuery($sqle);
}
else
{
$awba = $resultd[0]['awb'];
$sqlf = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awba."' limit 1";
$resultf = $db_handle->runSelectQuery($sqlf);
}
php mysql sql if-statement
if you want to stop it updating twice then the UPDATE statment would also have to be within your if/else block. Right now you seem to only have the select statements within that.
– ADyson
Nov 23 '18 at 14:33
1
BTW if you have multiple users on your system simultaneously then this system of picking the next unused slot is going to result in contention - i.e. people selecting and/or updating the same rows as each other. e.g. user1 runs select, slot 23 was available, but user2 also runs and gets slot 23 as available, then user1 runs update, and then user2 runs update (and thus overwrites user1's data). It would be better to just create the AWB records at the time you need them, surely, instead of creating them ahead or time. That or you have to find a way to lock the rows.
– ADyson
Nov 23 '18 at 14:34
I tried if else condition ... where is this if/else block? Also, what is the logic to decide PPD and COD. Your posted update query does not have anawb_type
condition (but select queries do).
– Parfait
Nov 23 '18 at 16:23
@ADyson i am using condition that ifstatus='unused'
, than only rows are going to update, so if user1 runs update ,slot 23 will become status='used'
, so when user2 also runs update , it will not update again right ? because alreadyslot 23 will become status='used'
, will it work ?
– vickey colors
Nov 24 '18 at 5:41
Yes but it will overwrite the order number with user2's order number, and user1's order number will be lost
– ADyson
Nov 24 '18 at 9:41
|
show 9 more comments
In php Page once we click on "Submit" button , in database we are saving order id, its working fine....
Requirement :
If payment is "Cash on delivery" , than i want to save order id in "awb_type : COD" row.... otherwise in "awb_type : PPD" row....
here is full code , track.php : https://pastebin.com/zLjpee7A , call.php : https://pastebin.com/4LkcxTYE
But orders are updating twice in table - one row in PPD & one in COD
Please let me know if you need more information....
Update 2 :
Now i tried below code, but whatever is payment_type , its saving only in awb_type column : PPD rows....
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
$resultc = $db_handle->runSelectQuery($sqlc);
$sqld = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
$resultd = $db_handle->runSelectQuery($sqld);
$payment_type='';
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$awb = $resultc[0]['awb'];
$sqle = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awb."' limit 1";
$resulte = $db_handle->runSelectQuery($sqle);
}
else
{
$awba = $resultd[0]['awb'];
$sqlf = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awba."' limit 1";
$resultf = $db_handle->runSelectQuery($sqlf);
}
php mysql sql if-statement
In php Page once we click on "Submit" button , in database we are saving order id, its working fine....
Requirement :
If payment is "Cash on delivery" , than i want to save order id in "awb_type : COD" row.... otherwise in "awb_type : PPD" row....
here is full code , track.php : https://pastebin.com/zLjpee7A , call.php : https://pastebin.com/4LkcxTYE
But orders are updating twice in table - one row in PPD & one in COD
Please let me know if you need more information....
Update 2 :
Now i tried below code, but whatever is payment_type , its saving only in awb_type column : PPD rows....
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
$resultc = $db_handle->runSelectQuery($sqlc);
$sqld = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
$resultd = $db_handle->runSelectQuery($sqld);
$payment_type='';
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$awb = $resultc[0]['awb'];
$sqle = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awb."' limit 1";
$resulte = $db_handle->runSelectQuery($sqle);
}
else
{
$awba = $resultd[0]['awb'];
$sqlf = "update ecomexpress_awb set orderid = '".$order_id."',status='used' WHERE awb ='".$awba."' limit 1";
$resultf = $db_handle->runSelectQuery($sqlf);
}
php mysql sql if-statement
php mysql sql if-statement
edited Nov 24 '18 at 6:50
vickey colors
asked Nov 23 '18 at 12:49
vickey colorsvickey colors
62115
62115
if you want to stop it updating twice then the UPDATE statment would also have to be within your if/else block. Right now you seem to only have the select statements within that.
– ADyson
Nov 23 '18 at 14:33
1
BTW if you have multiple users on your system simultaneously then this system of picking the next unused slot is going to result in contention - i.e. people selecting and/or updating the same rows as each other. e.g. user1 runs select, slot 23 was available, but user2 also runs and gets slot 23 as available, then user1 runs update, and then user2 runs update (and thus overwrites user1's data). It would be better to just create the AWB records at the time you need them, surely, instead of creating them ahead or time. That or you have to find a way to lock the rows.
– ADyson
Nov 23 '18 at 14:34
I tried if else condition ... where is this if/else block? Also, what is the logic to decide PPD and COD. Your posted update query does not have anawb_type
condition (but select queries do).
– Parfait
Nov 23 '18 at 16:23
@ADyson i am using condition that ifstatus='unused'
, than only rows are going to update, so if user1 runs update ,slot 23 will become status='used'
, so when user2 also runs update , it will not update again right ? because alreadyslot 23 will become status='used'
, will it work ?
– vickey colors
Nov 24 '18 at 5:41
Yes but it will overwrite the order number with user2's order number, and user1's order number will be lost
– ADyson
Nov 24 '18 at 9:41
|
show 9 more comments
if you want to stop it updating twice then the UPDATE statment would also have to be within your if/else block. Right now you seem to only have the select statements within that.
– ADyson
Nov 23 '18 at 14:33
1
BTW if you have multiple users on your system simultaneously then this system of picking the next unused slot is going to result in contention - i.e. people selecting and/or updating the same rows as each other. e.g. user1 runs select, slot 23 was available, but user2 also runs and gets slot 23 as available, then user1 runs update, and then user2 runs update (and thus overwrites user1's data). It would be better to just create the AWB records at the time you need them, surely, instead of creating them ahead or time. That or you have to find a way to lock the rows.
– ADyson
Nov 23 '18 at 14:34
I tried if else condition ... where is this if/else block? Also, what is the logic to decide PPD and COD. Your posted update query does not have anawb_type
condition (but select queries do).
– Parfait
Nov 23 '18 at 16:23
@ADyson i am using condition that ifstatus='unused'
, than only rows are going to update, so if user1 runs update ,slot 23 will become status='used'
, so when user2 also runs update , it will not update again right ? because alreadyslot 23 will become status='used'
, will it work ?
– vickey colors
Nov 24 '18 at 5:41
Yes but it will overwrite the order number with user2's order number, and user1's order number will be lost
– ADyson
Nov 24 '18 at 9:41
if you want to stop it updating twice then the UPDATE statment would also have to be within your if/else block. Right now you seem to only have the select statements within that.
– ADyson
Nov 23 '18 at 14:33
if you want to stop it updating twice then the UPDATE statment would also have to be within your if/else block. Right now you seem to only have the select statements within that.
– ADyson
Nov 23 '18 at 14:33
1
1
BTW if you have multiple users on your system simultaneously then this system of picking the next unused slot is going to result in contention - i.e. people selecting and/or updating the same rows as each other. e.g. user1 runs select, slot 23 was available, but user2 also runs and gets slot 23 as available, then user1 runs update, and then user2 runs update (and thus overwrites user1's data). It would be better to just create the AWB records at the time you need them, surely, instead of creating them ahead or time. That or you have to find a way to lock the rows.
– ADyson
Nov 23 '18 at 14:34
BTW if you have multiple users on your system simultaneously then this system of picking the next unused slot is going to result in contention - i.e. people selecting and/or updating the same rows as each other. e.g. user1 runs select, slot 23 was available, but user2 also runs and gets slot 23 as available, then user1 runs update, and then user2 runs update (and thus overwrites user1's data). It would be better to just create the AWB records at the time you need them, surely, instead of creating them ahead or time. That or you have to find a way to lock the rows.
– ADyson
Nov 23 '18 at 14:34
I tried if else condition ... where is this if/else block? Also, what is the logic to decide PPD and COD. Your posted update query does not have an
awb_type
condition (but select queries do).– Parfait
Nov 23 '18 at 16:23
I tried if else condition ... where is this if/else block? Also, what is the logic to decide PPD and COD. Your posted update query does not have an
awb_type
condition (but select queries do).– Parfait
Nov 23 '18 at 16:23
@ADyson i am using condition that if
status='unused'
, than only rows are going to update, so if user1 runs update , slot 23 will become status='used'
, so when user2 also runs update , it will not update again right ? because already slot 23 will become status='used'
, will it work ?– vickey colors
Nov 24 '18 at 5:41
@ADyson i am using condition that if
status='unused'
, than only rows are going to update, so if user1 runs update , slot 23 will become status='used'
, so when user2 also runs update , it will not update again right ? because already slot 23 will become status='used'
, will it work ?– vickey colors
Nov 24 '18 at 5:41
Yes but it will overwrite the order number with user2's order number, and user1's order number will be lost
– ADyson
Nov 24 '18 at 9:41
Yes but it will overwrite the order number with user2's order number, and user1's order number will be lost
– ADyson
Nov 24 '18 at 9:41
|
show 9 more comments
1 Answer
1
active
oldest
votes
Before I did't binded the payment_type with order_id, below code worked for me :
if(isset($_POST['order_id']) && $_POST['order_id']!='')
{
$order_id = $_POST['order_id'];
$payment_type=$_POST['payment_type'];
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
}
else
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
}
$resultc = $db_handle->runSelectQuery($sqlc);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447047%2fupdate-row-value-based-on-if-else-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Before I did't binded the payment_type with order_id, below code worked for me :
if(isset($_POST['order_id']) && $_POST['order_id']!='')
{
$order_id = $_POST['order_id'];
$payment_type=$_POST['payment_type'];
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
}
else
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
}
$resultc = $db_handle->runSelectQuery($sqlc);
add a comment |
Before I did't binded the payment_type with order_id, below code worked for me :
if(isset($_POST['order_id']) && $_POST['order_id']!='')
{
$order_id = $_POST['order_id'];
$payment_type=$_POST['payment_type'];
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
}
else
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
}
$resultc = $db_handle->runSelectQuery($sqlc);
add a comment |
Before I did't binded the payment_type with order_id, below code worked for me :
if(isset($_POST['order_id']) && $_POST['order_id']!='')
{
$order_id = $_POST['order_id'];
$payment_type=$_POST['payment_type'];
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
}
else
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
}
$resultc = $db_handle->runSelectQuery($sqlc);
Before I did't binded the payment_type with order_id, below code worked for me :
if(isset($_POST['order_id']) && $_POST['order_id']!='')
{
$order_id = $_POST['order_id'];
$payment_type=$_POST['payment_type'];
$sqlg="SELECT * FROM do_order where payment_type='".$payment_type."'";
$resultg = $db_handle->runSelectQuery($sqlg);
if($payment_type=="Cash on delivery")
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='COD' limit 1";
}
else
{
$sqlc = "select * from ecomexpress_awb WHERE status='unused' AND awb_type='PPD' limit 1";
}
$resultc = $db_handle->runSelectQuery($sqlc);
answered Nov 24 '18 at 11:54
vickey colorsvickey colors
62115
62115
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447047%2fupdate-row-value-based-on-if-else-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if you want to stop it updating twice then the UPDATE statment would also have to be within your if/else block. Right now you seem to only have the select statements within that.
– ADyson
Nov 23 '18 at 14:33
1
BTW if you have multiple users on your system simultaneously then this system of picking the next unused slot is going to result in contention - i.e. people selecting and/or updating the same rows as each other. e.g. user1 runs select, slot 23 was available, but user2 also runs and gets slot 23 as available, then user1 runs update, and then user2 runs update (and thus overwrites user1's data). It would be better to just create the AWB records at the time you need them, surely, instead of creating them ahead or time. That or you have to find a way to lock the rows.
– ADyson
Nov 23 '18 at 14:34
I tried if else condition ... where is this if/else block? Also, what is the logic to decide PPD and COD. Your posted update query does not have an
awb_type
condition (but select queries do).– Parfait
Nov 23 '18 at 16:23
@ADyson i am using condition that if
status='unused'
, than only rows are going to update, so if user1 runs update ,slot 23 will become status='used'
, so when user2 also runs update , it will not update again right ? because alreadyslot 23 will become status='used'
, will it work ?– vickey colors
Nov 24 '18 at 5:41
Yes but it will overwrite the order number with user2's order number, and user1's order number will be lost
– ADyson
Nov 24 '18 at 9:41