saravanataee Posted January 5, 2013 Share Posted January 5, 2013 Dear all, I am having the following php form, which has a table in that, i ill fill up the details and when i click Place order it will store the details into database. My query is that instead of place order it to add item, and for each time i click add item, the store data should be shown below the page where i am working inside a table serially. I mean basically displaying the rows in a grid.. Once it reaches the maximum screen size i should be able to scroll down to see all the items i have added. After all finished adding items i should then want to Place order which finally takes all my items into a single table value.. Any suggestion or idea how to start would be greatful. Thanks. <?php include("conndb.php"); function createoptions($table , $id , $field) { $sql = "select * from $table ORDER BY $field"; $res = mysql_query($sql) or die(mysql_error()); while ($a = mysql_fetch_assoc($res)) echo "<option value=\"{$a[$id]}\">$a[$field]</option>"; } // mysql_connect('localhost', 'root', ''); // mysql_select_db('inventorydb'); ?> <!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" /> <title>Place an Order</title> <script language="javascript src="code.js"> </script> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> <style> #entrydt1 { margin-left: 100px; } #orderid1 { margin-left: 107px; } #orderdt1 { margin-left: 94px; } #itemid { margin-left: 142px; } #qtyid { margin-left: 122px; } #packid { margin-left: 120px; } #qtynoid { margin-left: 80px; } #Poid { margin-left: 80px; } #resetid { margin-left: 80px; } #clearid { margin-left: 80px; } #Name { margin-left: 50px; width:100px;} </style> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" charset="utf-8"> $(function(){ $("select#category").change(function(){ $.getJSON("select.php",{category: $(this).val(), ajax: 'true'}, function(j){ var options = ''; for (var i = 0; i < j.length; i++) { options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>'; } $("select#subcategory").html(options); }) }) $("select#subcategory").change(function(){ $.getJSON("select.php",{subcategory: $(this).val(), ajax: 'true'}, function(j){ var options = ''; for (var i = 0; i < j.length; i++) { // options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>'; options = '<input type="text" name="subcat2" value="' + j[i].optionDisplay + '" />'; } $("div#subcategory2").html(options); }) }) }) </script> <script>function calculate() { document.getElementById("t8").value = parseFloat(document.getElementById("subcat2").value) * (parseFloat(document.getElementById("MRP").value)*(parseFloat(document.getElementById("t7").value)/100)); } </script> </head> <body> <h1>Place an Order</h1> <form method="post"> <table border='1' > <tr> <td><label for="t1">Item</label></td> <td><label for="t2">Quantity</label></td> <td><label for="t2">Packing</label></td> <td><label for="t2">Quantity in NO's</label></td> <td><label for="t2">MRP/RATE</label></td> <td><label for="t2">Discount</label></td> <td><label for="t2">Amount</label></td> </tr> <tr> <td> <select name="cat" id="category"> <option value="-1">--Select--</option> <?php createoptions("category", "cat_id", "category"); ?> </select> </td> <td><input name="t3" id="t3" size="10" value=""></td> <td> <select name="subcat" id="subcategory"> </select> </td> <td> <!-- <select name="subcat2" id="subcategory2"> </select> <input type="text" name="subcat2" value="" id="subcategory2" /> --> <div id="subcategory2"> </div> </td> <td><select name="MRP" id="MRP"> <option value=""><--Select--></option> <?php $sql = "SELECT Mrprate FROM mrp"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['Mrprate'] . "' >" . $row['Mrprate'] . "</option>"; } ?></td> <td><input name="t7" id="t7" size="10" placeholder="40%" value=""></td> <td><input name="t8" id="t8" size="10" value="" onchange="calculate()"></td> </tr> <tr> <td><input type="submit" name="submit" value="Place Order"></td> <td><input type="submit" name="submit1" value="Reset"></td> </tr> </table> </form> </body> </html> <?php if (isset($_POST['submit'])) { include 'db.php'; $item=$_POST['cat'] ; $qty= $_POST['t3'] ; $pack= $_POST['subcat'] ; $qtyno= $_POST['subcat2'] ; $mrp= $_POST['MRP'] ; $dis= $_POST['t7'] ; $amt= $_POST['t8'] ; $query= mysql_query("INSERT INTO `po`(Item,Quantity,Packing, QuantityNO, MRP, Discount, Amount) VALUES ('$item','$qty','$pack','$qtyno','$mrp','$dis','$amt')"); if(!$query) { die('Query Failed with exception'.mysql_error()); } else{ echo"Thanks for the input"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/272723-want-to-display-inserted-row-inside-a-table-in-php-form/ Share on other sites More sharing options...
50r Posted January 5, 2013 Share Posted January 5, 2013 There are two problem actually why no one has replyed to this post. 1 your question is quite not clear, 2 the code that you post is not well indented which makes it hard to read. Try by explaining what the problem is. do you want to retrieve data from a database? after you insert it or what? Quote Link to comment https://forums.phpfreaks.com/topic/272723-want-to-display-inserted-row-inside-a-table-in-php-form/#findComment-1403417 Share on other sites More sharing options...
saravanataee Posted January 6, 2013 Author Share Posted January 6, 2013 Hi 50r, Yes, presently i have a table with one row in which i fill the five fields and when i click add item i store them into database. What i look for is, whenever i insert an item i want to display it in the same page below my present table. No mater how many items i insert, all should be displayed and i should be able to scroll and see them..! Quote Link to comment https://forums.phpfreaks.com/topic/272723-want-to-display-inserted-row-inside-a-table-in-php-form/#findComment-1403610 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.