Jump to content

Checking row values within while using if stmt


mythri
Go to solution Solved by mythri,

Recommended Posts

Hello ,

 

I am trying to update a record in my table if the particular value exists in the rows of a table. But my if-else not working properly. I am not getting where i am going wrong.

 

here is my table authorization, where i define authorization % with min and max.

post-168283-0-85982500-1418470514_thumb.jpg

 

after adding line items, before display i will check whether any one of the line item discount lies within this min and max and also checks whether authorization is required (required='Yes'/'No')  for that discount in my authorization table.  If authorization required then i will update that order number as authorized. 

 

here is my line items table

 

post-168283-0-05347900-1418470803_thumb.jpg

 

I am doing like this

while($row=mysql_fetch_array($query))
{
$dis1 = "SELECT auth_id, auth_min, auth_max, required FROM sales_authorisation";
$dis2 = mysql_query($dis1) or die (mysql_error());

while($d1 = mysql_fetch_array($dis2))
{
	$min = $d1['auth_min'];
	$max = $d1['auth_max'];
	$req = $d1['required'];
	//echo $req;
	
if( ($min <= ($row['discount'])) && ($max >= ($row['discount'])) && ($req='Yes'))
{
$auth = "UPDATE orders SET authorise='No' WHERE order_id=".$order_id."";
echo "hello";
}
else
{

$auth = "UPDATE orders SET authorise='Yes' WHERE order_id=".$order_id."";

}
$auth1 = mysql_query($auth) or die (mysql_error());

}

?> 

<tr> 
<td><?php echo $counter++; ?></td>
<td><?php echo $row['itemname']; ?> - <?php echo $row['uom']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo number_format($row['selling_price'],2); ?></td>
<td><?php echo $row['discount']; ?> %</td>
<td><?php echo $row['tname']; ?>-<?php echo $row['rate']; ?> %</td>
<td><?php echo $row['freight']; ?></td>
<td><?php echo number_format($row['total'],2); ?></td>
 
 </tr> 

While loop is for displaying line items for the order.

 

But my if condition doesn't works :(. Not getting how to do it. please suggest 

 

 

 

Link to comment
Share on other sites

In addition to what boompa pointed out your whole code logic doesn't make to much sense... You need to rethink it.

Your sales-authorisation table is going to have only one record or many?

Is there any relation between the sales-authorisation and the order, each order item or it is applied globally?

Do you realize that you could be updating your order over and over in the inner loop?, and for each order item?..

Edited by mikosiko
Link to comment
Share on other sites

While loop is for displaying line items for the order.

 

 

if the purpose of this code is to display things, it shouldn't be updating any database table. any value needed in the orders table should have been gotten when the information was inserted into the orders table or as a separate step, not as the display step.

 

you shouldn't mix POST method functionality that changes information on the server with GET method functionality that displays information. in fact, after you successfully (without any errors) process a POST method form submission, you should be doing a header() redirect to the same exact url of the page to get the browser to forget the form data so that it won't try to resubmit it. this will cause a GET request for the page and your code should then display the current information for the page.

 

edit: and if you need to get the sales_authorisation information for items in a cart/order, you should do it in the query getting the cart/order information using a JOINed query. you should not run select queries inside of loops.

  • Like 1
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.