skoobi Posted November 9, 2009 Share Posted November 9, 2009 Hi im having a few problems with trying to get the coding right on a orders list ive done (or trying to do) for a custom shopping cart im making... For some reason it comes up with all the orders in stead of 1. i.e. If there i start from scratch ill have order number 1 which will have the order in but if i create another order it displays order number 2 twice with both the customers details on... Heres the code: <?php include ('../includes/db.php'); include('search.php'); ?> <!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=utf-8" /> <title>Orders</title> </head> <body> <a href="orders.php">Refresh</a> || <a href="admin.php">Back to Admin</a> <br/><br/> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <input type="submit" name="submit" value="Search!" /> || First Name: <input type="checkbox" name="firstname" value="on" <?php echo isset($_GET['firstname'])?"checked":''; ?> /> || Last Name: <input type="checkbox" name="lastname" value="on" <?php echo isset($_GET['lastname'])?"checked":''; ?> /> || House Name: <input type="checkbox" name="address1" value="on" <?php echo isset($_GET['address1'])?"checked":''; ?> /> || Post Code: <input type="checkbox" name="zip" value="on" <?php echo isset($_GET['zip'])?"checked":''; ?> /> </form> <br /> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <?php echo (count($results) > 0)?"Your search for '{$searchTerms}' returned:<br /><br />" . implode("", $results):""; ?> <?php $result = mysql_query("SELECT * FROM customers INNER JOIN order_detail ORDER BY orderid DESC"); echo "<table border='1'> <tr> <th>Order Number</th> <th>Firstname</th> <th>Lastname</th> <th>Address 1</th> <th>Address 2</th> <th>City</th> <th>State</th> <th>Post Code</th> <th>Phone</th> <th>Payment</th> <th>Price</th> <th>Total</th> <th>Payed</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['orderid'] . "</td>"; echo "<td>" . $row['firstname'] . "</td>"; echo "<td>" . $row['lastname'] . "</td>"; echo "<td>" . $row['address1'] . "</td>"; echo "<td>" . $row['address2'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['zip'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; echo "<td>" . $row['payment'] . "</td>"; echo "<td>£" . $row['price'] . "</td>"; echo "<td>£" . $row['total'] . "</td>"; echo "<td>" . $row['payed'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close(); ?> </body> </html> Im completely stuck on this as im no php or mysql gurru... so any help or info would be greatfull... Cheers Chris Quote Link to comment https://forums.phpfreaks.com/topic/180869-sql-and-php-order-list-script-problems/ Share on other sites More sharing options...
Psycho Posted November 9, 2009 Share Posted November 9, 2009 When doing a JOIN without any criteria the code will join every record from the first table with every record from the second table. You need to proivde some 'logic' on which records you want joined to the others. Assuming the 'customers' table has an ID field aqnd the 'order_detail' table has a foreign key for the customer ID the query might look like this: SELECT * FROM customers INNER JOIN order_detail ON customers.id = order_detail.customer_id ORDER BY orderid DESC Not knowing your DB structure, that is only an example of how it should look like Quote Link to comment https://forums.phpfreaks.com/topic/180869-sql-and-php-order-list-script-problems/#findComment-954178 Share on other sites More sharing options...
skoobi Posted November 10, 2009 Author Share Posted November 10, 2009 Thanks for your reply ill give it a shot today... Ive just been looking over some Mysql tutorials so i can better understand it... Quote Link to comment https://forums.phpfreaks.com/topic/180869-sql-and-php-order-list-script-problems/#findComment-954823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.