Schlo_50 Posted November 29, 2007 Share Posted November 29, 2007 Ok, this isn't meant to be a double post but i apologise if it comes accross that way! I have a script which calls and displays items from my database, each item has a unique product id. The idea is that the user views the page full of items and clicks a checkbox or any efficient method (suggestions) to select one or more items they want to purchase. For each item they select i want the product id of each to be sent into my database into one field separated by commas. What i need for the next part of the script is some code which will work with the $ProductId's to do what i want it to. Any help? Im seriously stuck and need some ideas about how to achieve my goal. <?php $sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg()); $prevCat=''; while($row = odbc_fetch_array($sql2)) { $Category = $row["CategoryName"]; $ProductId = $row["ProductId"]; $ProductName = $row["ProductName"]; $Price = $row["Price"]; // has category changed // if so, print it if ($Category != $prevCat) { echo "<h2>$Category</h2>"; } echo 'Item Code: ', $ProductId, '<br/>Item Name: ', $ProductName, '<br/><br/>Price: £', $Price, '<input name="code[]" type="text" size="2" /><br/><br/>'; $prevCat = $Category; } ?> Thanks Link to comment https://forums.phpfreaks.com/topic/79391-database-help/ Share on other sites More sharing options...
adam291086 Posted November 29, 2007 Share Posted November 29, 2007 ok at the moment you have all the products being echo onto a page. You need to set this page up as a form. That will send the users information to a php page where we can add stuff into the database. Get that set up first. Link to comment https://forums.phpfreaks.com/topic/79391-database-help/#findComment-401899 Share on other sites More sharing options...
Barand Posted November 29, 2007 Share Posted November 29, 2007 For each item they select i want the product id of each to be sent into my database into one field separated by commas. What you should want is each selected product_id to be written to its own record along with the customer_id eg[pre] cust_orders -----+-----------+-----------+ id | cust_id | prod_id | -----+-----------+-----------+ 1 | 123 | 4321 | 2 | 123 | 4095 | 3 | 123 | 3255 | 4 | 123 | 2102 | -----+-----------+-----------+ 5 | 124 | 1121 | 6 | 124 | 4095 | -----+-----------+-----------+ 7 | 125 | 3255 | 8 | 125 | 1111 | -----+-----------+-----------+ [/pre] Link to comment https://forums.phpfreaks.com/topic/79391-database-help/#findComment-401907 Share on other sites More sharing options...
Schlo_50 Posted November 29, 2007 Author Share Posted November 29, 2007 Ok, like this you mean? form name="the_form" id="the_form" method="post" action="<?php $_SERVER[php_SELF]; ?>"> <?php $sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg()); $prevCat=''; while($row = odbc_fetch_array($sql2)) { $Category = $row["CategoryName"]; $ProductId = $row["ProductId"]; $ProductName = $row["ProductName"]; $Price = $row["Price"]; // has category changed // if so, print it if ($Category != $prevCat) { echo "<h2>$Category</h2>"; } echo 'Item Code: ', $ProductId, '<br/>Item Name: ', $ProductName, '<br/><br/>Price: £', $Price, '//need some way of selecting item here, checkbox?<br/><br/>'; $prevCat = $Category; } ?> <hr /> (Order Notes- If you have any comments to make about any of the products you are ordering please state them below.)<br /> <textarea name="ProductNotes" cols="50" rows="5"></textarea><br /><br /> <input name="submit" type="Submit" value="Submit" /> </p> </form> Link to comment https://forums.phpfreaks.com/topic/79391-database-help/#findComment-401968 Share on other sites More sharing options...
aschk Posted November 29, 2007 Share Posted November 29, 2007 Your html for the product options should look like : while(blah blah blah){ echo '<input type="checkbox" name="products[]" value="$EachProductIDHere" />'; } Link to comment https://forums.phpfreaks.com/topic/79391-database-help/#findComment-401971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.