Page 1 of 1

PHP & MYSQL if then else statement

Posted: Sun Nov 29, 2009 2:02 pm
by chrishawkins
Hello,

I have been able to put together some php code that shows a daily sales report of items that have been sold that day. The code selects from a table in my database, looks for the value under payment_status and when the value is confirmed it echos the results.

However, what I need to do now, is when it finds that the payment_status is confirmed and after it has been displayed to me, I need it to update the field named printed in that table to a value I set (i.e. printed). Also, the next time I run the script, I will need for it to do the same thing, only I will need it to now look for the payment_status='confirmed' as well as printed='printed' and only echo the results of payment_status='confirmed' if printed="null".

Can someone help me out with this?

Here is the code I have thus far;

Code: Select all

 
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("my_db", $con);
 
$result = mysql_query("SELECT * FROM auction_winners
WHERE payment_status='confirmed' ORDER BY bid_amount");
 
echo "<table border='1'>
<tr>
<th>Auction ID</th>
<th>Bid Amount</th>
</tr>";
 
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['auction_id'] . "</td>";
  echo "<td>" . $row['bid_amount'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
 
mysql_close($con);
?>

Re: PHP & MYSQL if then else statement

Posted: Thu Dec 03, 2009 11:07 pm
by ramblin54321
Place the following on line 28.

mysql_query("UPDATE my_db SET printed = 'yes'
WHERE payment_status='confirmed' ;

change line 12 to the following:
WHERE payment_status='confirmed' AND printed=' ' ORDER BY bid_amount");