Jump to content

gavin1512

Members
  • Posts

    31
  • Joined

  • Last visited

    Never

Everything posted by gavin1512

  1. Good Evening All, I am working on an internal order system and I am currently trying to input some reporting features, I am using a mySQL database and I have got the report working so its groups the orders by department and counts the number of order and now I am trying to get the total spending, unfortuntely this field is not in the database so for each individual order I am going into each individual product and multiplying price by quantity. Here is the code I am trying to use, but the total are coming up as £0 presently: .....$date1 = $_POST['date1']; $date2 = $_POST['date2']; $query="select COUNT(orders.orderid) as num_orders, department from productorder, orders, employee where productorder.orderid = orders.orderid AND employee.username = orders.username AND `date` BETWEEN '" . $date1 . "' AND '" . $date2 . "' Group BY department Order BY num_orders DESC"; $result=@mysql_query($query,$connection) or die("Unable to perform query<br>$query");...... <?php while($row= mysql_fetch_array($result)) { ?> <tr> <td><?php echo $row['department']?></td> <td><?php echo $row['num_orders'] ?></td> <?php $query2="select * from productorder, orders, employee where productorder.orderid = orders.orderid and employee.username = orders.username AND employee.department= '".$row['department']."' and productorder.orderid= '".$row['orderid']."'"; $result2=@mysql_query($query2,$connection) or die("Unable to perform query<br>$query2"); while($row2=mysql_fetch_array($result2)) { ?> <?php $total = $row2['quantity'] * $row2['price'] ?> <?php $total2 = $total2 + $total ?> <?php } ?> <td>£<?php echo $total2 ?></td> <td><?php $avg = $total2/$row['num_orders'] ?>£<?php echo $avg ?></td> </tr> <?php } ?>
  2. Brilliant! if only all problems were that easy Cheers
  3. Good Morning, Having a small issue with displaying results from the database in a text box, it reads from the SQL database fine and dispalys part of the record but only the first word of the record, anything after a space is not displayed Is there a way of displaying the whole record not just the first word? and is it possible to hide the box and just display the data? it needs to be displayed ina text box due to the multiple GET statements used on the page. The code I am using for the text boxes is: <td><input name="type" type="text" readonly="true" Value=<?php echo $row['type']?> /></td> Thanks in advance
  4. Good Afternoon, I am having a slight issue displaying the results of a count query. I have tested it in the SQL section of PHPmyAdmin and the query runs fine and gets 5 results and the appropriate counts. Here is my SQL Query~: $query="select COUNT(orderid),employee.username from orders, employee where employee.username = orders.username AND `date` BETWEEN '" . $date1 . "' AND '" . $date2 . "' Group BY orders.username"; $result=@mysql_query($query,$connection) or die("Unable to perform query<br>$query"); I am displaying the results with: <?php while($row= mysql_fetch_array($result)) { ?> <tr> <td> </td> <td><?php echo $row['employee.username']?></td> <td><?php echo $row['COUNT(orderid)'] ?></td> <td> </td> <td> </td> </tr> <?php } ?> I have tried removing the date function but that does not seem to be the problem. Any assistance would be much appreciated
  5. Good Morning, I am working on a basic internal order system with my SQL database backbone. The problem I am having is when writing from my array to the database. In the basket page it displays all items added to the basket array, and next to each item is a textbox to enter the quantity, when writing to the database it on takes the value in the last quantity box and inserts that value for all products. Here is my code for writing to the database: <?php session_start(); require "connect.php"; $quantity = $_GET['quantity']; $username = $_SESSION['username']; $order = $username.date("d/m/y : H:i:s", time()); $query = "insert into orders values ('".$order."','".$username."','pending approval','".date("d-M-Y")."')"; $result = mysql_query($query, $connection) or die (mysql_error()); $orderid = mysql_insert_id($connection); foreach($_SESSION['order'] as $key => $product) { $query = "insert into productorder values ('".$order."','".$_SESSION['order'][$key]['productnumber']."','".$quantity."', 'pending approval','".$_SESSION['order'][$key]['price']."')"; $result = mysql_query($query, $connection) or die ("Unable to perfom query<br>$query"); } unset($_SESSION['order']); $message3 = "Your Order has been sent to your manager for approval"; header("Location: productsearch.php?var=productnumber&message3=$message3"); exit(); ?> I not sure if I need a foreach loop to insert the quantity or the box needs to be renamed to include the $key or if it can be related to the productnumber field
  6. Can anyone help me here problem is still about.... would be much appreciated
  7. No sorry i do not think I have made myself clear with my problem, i do not wish to increment the value by one when repeated add, there is a text box where the quantity is manually written next to each product. If i were to enter 20 10 and 15 against 3 products it will just write 20 3 times a there is no for each loop associated with the productnumber [key]
  8. Good Afternoon people, I am currently working on a basic internal ordering system, the products are read from the database then if the user wants the product it is added to an array. When they go to the check out they have the option of adding a quantity, the problem I am having is that when I confirm the order and write it to the orders table it will only read the first value and repeat that. I have tried various loops to add the quantity to the array of straight to the orders database. This in my current confirmorder.php script: <?php session_start(); require "connect.php"; $quantity = $_GET['quantity']; $username = $_SESSION['username']; $order = $username.date("d/m/y : H:i:s", time()); $query = "insert into orders values ('".$order."','".$username."','pending approval','".date("d-M-Y")."',1000)"; $result = mysql_query($query, $connection) or die (mysql_error()); $orderid = mysql_insert_id($connection); foreach($_SESSION['order'] as $key => $product) { $query = "insert into productorder values ('".$order."','".$_SESSION['order'][$key]['productnumber']."','".$quantity."', 'pending approval','".$_SESSION['order'][$key]['price']."')"; $result = mysql_query($query, $connection) or die ("Unable to perfom query<br>$query"); } unset($_SESSION['order']); $message3 = "Your Order has been sent to your manager for approval"; header("Location: productsearch.php?var=productnumber&message3=$message3"); exit(); ?> I am guessin the text box name with have to be altered to reference the key, at the moment it is just <td width="198"><input name="quantity" type="text"></td>
  9. And when this is resolved can you please give me this code as well
  10. Thank you for your assistance, I have updated my form fine just having a slight problem on the script I have the foreach loop of: { $query = "insert into productorder values ('".$order."','".$_SESSION['order'][$key]['productnumber']."','".$quantity."', 'pending approval','".$_SESSION['order'][$key]['price']."')"; $result = mysql_query($query, $connection) or die ("Unable to perfom query<br>$query"); } would I need to put the foreach ($_GET['quantity'] as $key=>$quantity) loop before hand and update the ".$quantity." to $_GET['quantity'][$key]?
  11. Good Afternoon, I am having a slight issue in writing mulitple text box entries to the database, basically I have a shopping basket and next to each item is a textbox with the name quantity, the items are displayed using a loop to display entries from an array: foreach($_SESSION['order'] as $key => $product){ ?> <tr> <td><?php echo $_SESSION['order'][$key]['productnumber']?></td> <td><?php echo $_SESSION['order'][$key]['type']?></td> <td><?php echo $_SESSION['order'][$key]['description']?></td> <td>£<?php echo $_SESSION['order'][$key]['price']?></td> <td width="198"><input name="quantity" type="text"></td> the problem I am having is that it will only take the first entry for quantity and put that against each item and ignore the other text boxes. I am just using a simple GET statement, does the GET statement need to be put into a loop?
  12. Thank you! thought it would be a simple character like that
  13. Good Afternoon All, I having a bit of trouble passing back 2 variables in a header, was wondering if it is possible and how best to do it, here is the code I attempted to use: header("Location:productsearch.php?var=productnumber?message=$message1"); As you can see I am trying to pass a the productnumber and message back to a page. Can anyone help me please
  14. Unfortunately not, the system is due to replace a current basic paper based system and my client would like to keep the format of the order ID
  15. Good evening All, I have a slight issue with generating an auto increment that adds on the end of two variables. Basically I have an order ID which is made up of a username and date: $order = $username.date("d-M-Y"); But this restricts the users to one order per day, can some one please assist me to have a single digit after the username and date which increases if that order ID exists. Thank You
  16. I just tried to $_GET as a coudln't think of any other possibility, as being inexperienced with PHP. I have the GET methods in the addtoorder.php shown below. I can either get the values from text boxes or from the database, but have not got from both in the same form. Hope this makes my problem clearer. Is this solved using the POST method? <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:home.php"); exit(); } // product array to store product details $product = array(); $product['productnumber']= $_GET['productnumber']; $product['type']= $_GET['type']; $product['description']= $_GET['description']; $product['price']= $_GET['price']; $product['quantity'] = $_GET['quantity']; $found = false; if(isset($_SESSION['order'])){ foreach($_SESSION['order'] as $key => $anotherproduct) { if ($_SESSION['order'] [$key] ['productnumber'] == $_GET['productnumber']) { $found = true; } } } //add the print to the cart if not there already if ($found ==false) { $_SESSION['order'] [] = $product; } header("Location:productsearch.php"); ?>
  17. I guessing the problem is with the &quantity=<?php $_GET['quantity'], i just put that in to try.
  18. here is the code for the whole form (sorry is a bit untidy I am using dreamweaver) <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:home.php"); exit(); } require "connect.php"; if (($_GET['text'] == "") || ($_GET['field'] == "*")) { $query = "SELECT * FROM product ORDER BY productnumber limit 0, 10"; } else { $query = "SELECT * FROM product WHERE ".$_GET['field']. " like '%".$_GET['text']."%' ORDER BY productnumber"; } $result = @mysql_query($query, $connection) or die ("Unable to perform query<br />$query"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- TemplateBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- TemplateEndEditable --> <!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable --> <style type="text/css"> <!-- #Layer1 { position:absolute; width:988px; height:680px; z-index:1; left: 215px; top: 104px; } #Layer2 { position:absolute; width:389px; height:435px; z-index:2; left: 17px; top: 107px; } #Layer3 { position:absolute; width:200px; height:51px; z-index:3; left: 6px; top: -86px; } #Layer4 { position:absolute; width:267px; height:39px; z-index:3; left: 713px; top: -73px; } .style1 {font-family: Arial, Helvetica, sans-serif} --> </style> </head> <body> <p class="style1"><img src="back.jpg" width="1199" height="652" align="top" /></p> <?php switch ($_SESSION['access']) { case 'User': include('user side.php'); break; case 'Manager': include('manager side.php'); break; case 'Fulfilment': include('fulfil side.php'); break; case 'Admin': include('admin side.php'); break; } ?> <div class="style1" id="Layer1"> <table width="979" border="0"> <form method="get" action="productsearch.php" name="productsearch"> <tr> <td width="136"> </td> <td width="157"> </td> <td width="172"> </td> <td width="175"> </td> <td width="152"> </td> </tr> <tr> <td><div id="Layer3"> <table width="200" border="0"> <tr> <td height="38">Product Search Page </td> </tr> </table> </div></td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><p>Please enter search criteria </p></td> <td><input name="text" type="text" id="text" /></td> <td><p><select name="field" id="field"> <option value="*">Choose category</option> <option value="productnumber">Product Number</option> <option value="type">Product Type</option> <option value="description">Description</option> <option value="price">Price</option> </select></p></td> <td><input name="search" type="submit" id="search" value="Search" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td><div align="right">Page</div></td> <td><a href="productsearch.php">1 </a><a href="productsearch2.php">2 </a><a href="productsearch3.php">3 </a><a href="productsearch4.php">4</a></td> </tr> </form> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><strong>Product Number </strong></td> <td><strong>Product Type </strong></td> <td><strong>Description</strong></td> <td><strong>Price</strong></td> <td><strong>Quantity</strong></td> <td width="161"><div align="center"><strong>Add to Order</strong></div></td> </tr> <?php while($row= mysql_fetch_array($result)) { ?> <tr> <form action="addtoorder.php" method="get"> <td><?php echo $row['productnumber']?></td> <td><?php echo $row['type']?></td> <td><?php echo $row['description']?></td> <td><?php echo $row['price']?></td> <td><input name="quantity" type="text"></td> <td><div align="center"><a href="addtoorder.php?productnumber=<?php echo $row['productnumber']?> &type=<?php echo $row['type']?> &description=<?php echo $row['description']?> &price=<?php echo $row['price']?> &quantity=<?php $_GET['quantity']?> " > [+] </a></div></td> </form> </tr> <?php } ?> </table> </div> <p class="style1"> </p> </body> </html>
  19. Good afternoon all, I am havign another small problem that is becoming quite frustrating...Basically when selecting a product from a list of search results for the user to add to the basket, I have a text box called "quantity" which the user enters the Quantity then clicks the add button which links to the adduser script. At the moment it is taking all the DB values fine but not the quantity, at the bottom of page when I hover over the button it shows all the values e.g. &productnumber = 00E140dn &price = 342.10 but after $quantity = it is just blank. Here is the code I am using on the href button: <div align="center"><a href="addtoorder.php?productnumber=<?php echo $row['productnumber']?> &type=<?php echo $row['type']?> &description=<?php echo $row['description']?> &price=<?php echo $row['price']?> &quantity=<?php $_GET['quantity']?> " > [+] </a></div>
  20. thank you for your assistance I will work on implementing that function now.
  21. Good Afternoon, I am having some issues when adding items to an array, it is a style of shopping basket and the if statement I am using is still allowing multiples of one product to be added to the basket. Below is my code: <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:home.php"); exit(); } $product = array(); $product['productnumber']= $_GET['productnumber']; $product['type']= $_GET['type']; $product['description']= $_GET['description']; $product['price']= $_GET['price']; $product['quantity'] = $_GET['quantity']; $_SESSION['order'] [] = $product; $found = false; if(isset($_SESSION['order'])){ foreach($_SESSION['order'] as $key => $anotherproduct) { if ($_SESSION['order'] [$key] ['productnumber'] == $_GET['productnumber']) { $found = true; } } } //add the product to the cart if not there already if ($found ==false) { $_SESSION['order'] [] = $product; } header("Location:productsearch.php"); ?>
  22. still the same problem, it sending through the product number to the remove.php script but not removing it from the array
  23. Good Day All, I am surrently working on an internal order system, I am able to write the items to my array called 'order' but my code for removing from an array is not working at all and just goes straight to the header. Here is the code I am using. <?php session_start(); foreach($_SESSION['order'] as $key => $product){ if ($_SESSION['order'][$key]['productnumber'] == $_GET['productnumber']){ unset($_SESSION['order'][$key]); } } header("Location: productsearch.php"); exit(); ?>
  24. I would like to thank everyone for their help, i altered the header to include header('Location: admin home.php') and it has fixed the problem. CHEERS
×
×
  • 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.