Jump to content

dioti

New Members
  • Posts

    3
  • Joined

  • Last visited

dioti's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @Barand ooh true, sorry it's pretty late here so i forgot about WHERE clause, but where should i add it though ? sorry for my questions, it's just that this is the only function left and i want to finish this so i can get back to javascript and python again.
  2. @Barand thank you, i already found the solution few mins ago, but can you write me a code or tell me how to put the condition to my query ? new code: <?php $conn = $pdo->open(); try{ $stmt = $conn->prepare("SELECT *, sales.id AS salesid FROM sales LEFT JOIN users ON users.id=sales.user_id ORDER BY sales_date DESC"); $stmt->execute(); foreach($stmt as $row){ $stmt = $conn->prepare("SELECT * FROM details LEFT JOIN products ON products.id=details.product_id WHERE details.sales_id=:id"); $stmt->execute(['id'=>$row['salesid']]); $total = 0; foreach($stmt as $details){ $subtotal = $details['price']*$details['quantity']; $total += $subtotal; } if($row['Confirmed'] == 0){ echo " <tr> <td class='hidden'></td> <td>".date('M d, Y', strtotime($row['sales_date']))."</td> <td>".$row['firstname'].' '.$row['lastname']."</td> <td>".$row['country'].' , '.$row['city']." , ".$row['address']."</td> <td width='25px;'>&#8378; ".number_format($total, 2)."</td> <td width='18px;'><button type='button' class='btn btn-info btn-sm btn-flat transact' data-id='".$row['salesid']."'><i class='fa fa-search'></i> View</button></td> <form action='' method='post'> <td width='18px;'> <input type='hidden' name='confirm' value='1'> <input class='btn btn-success btn-sm btn-flat' type='submit' value='Confirm'> </td> </form> </tr> "; if(isset($_POST['confirm']) && $_POST['confirm']) { $stmt = $conn->prepare("UPDATE sales SET Confirmed = 1 WHERE id = '".$row['salesid']."'"); $stmt->execute(); } } } } catch(PDOException $e){ echo $e->getMessage(); } $pdo->close(); ?>
  3. I don't know many things in php yet so i need help to find out how to set a button to change value of "Confirmed" row from 0 to 1 in table "sales". I commented "This Button" at the beginning of the button i want to do the process. <?php $conn = $pdo->open(); try{ $stmt = $conn->prepare("SELECT *, sales.id AS salesid FROM sales LEFT JOIN users ON users.id=sales.user_id ORDER BY sales_date DESC"); $stmt->execute(); foreach($stmt as $row){ $stmt = $conn->prepare("SELECT * FROM details LEFT JOIN products ON products.id=details.product_id WHERE details.sales_id=:id"); $stmt->execute(['id'=>$row['salesid']]); $total = 0; foreach($stmt as $details){ $subtotal = $details['price']*$details['quantity']; $total += $subtotal; } if($row['Confirmed'] == 0){ echo " <tr> <td class='hidden'></td> <td>".date('M d, Y', strtotime($row['sales_date']))."</td> <td>".$row['firstname'].' '.$row['lastname']."</td> <td>".$row['country'].' , '.$row['city']." , ".$row['address']."</td> <td width='25px;'>&#8378; ".number_format($total, 2)."</td> <td width='18px;'><button type='button' class='btn btn-info btn-sm btn-flat transact' data-id='".$row['salesid']."'><i class='fa fa-search'></i> View</button></td> <td width='18px;'> <!-- This Button --> <button type='button' class='btn btn-success btn-sm btn-flat confirm' data-id='".$row['salesid']."'><i class='fa fa-check'></i> Confirm</button></td> </tr> "; } } } catch(PDOException $e){ echo $e->getMessage(); } $pdo->close(); ?>
×
×
  • 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.