-1

This is my table. I am developing billing application in core php mysql. Each row insert into table means need more memory, so I need to insert an one customer bill in a single row with all values separated by comma,

        <table id="options-table" border="1">   
                                            <tbody><tr>
                                            <th>S.NO</th>
                                                <th>Product Name</th>                                                   
                                                <th>Qty</th>
                                                <th>Rate ($)</th>
                                                <th>Total ($)</th>
                                                <th>Option</th>
                                            </tr>                               

                                            <tr>
                                            <td><span id="snum">1.</span></td>
                                                <td><input type="text" name="productname[]" required="" class="ui-wizard-content valid"></td>
                                                <!--<td><input type="text"  style="width:80px;" name="itemcode" /></td> -->
                                                <td><input type="text" class="qty ui-wizard-content valid" name="qty[]" required=""></td>
                                                <td><input type="text" class="rate ui-wizard-content valid" name="rate[]" required=""></td>
                                                <td><input type="text" class="tcost ui-wizard-content valid" name="tcost[]" readonly=""></td>
                                                <td><input type="button" class="del btn-danger ui-wizard-content" value="Delete"></td>
                                            </tr>                  
                                            <tr>
                                            <td><span id="snum">2.</span></td>
                                                <td><input type="text" name="productname[]" required="" class="ui-wizard-content valid"></td>
                                                <!--<td><input type="text"  style="width:80px;" name="itemcode" /></td> -->
                                                <td><input type="text" class="qty ui-wizard-content valid" name="qty[]" required=""></td>
                                                <td><input type="text" class="rate ui-wizard-content valid" name="rate[]" required=""></td>
                                                <td><input type="text" class="tcost ui-wizard-content" name="tcost[]" readonly=""></td>
                                                <td><input type="button" class="del btn-danger" value="Delete"></td>
                                            </tr><tr><td><span id="snum3">3.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td>  <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost" name="tcost[]" readonly=""></td><td><input type="button" class="del btn-danger" value="Delete"></td></tr><tr><td><span id="snum3">4.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td>  <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost" name="tcost[]" readonly=""></td><td><input type="button" class="del btn-danger" value="Delete"></td></tr><tr><td><span id="snum3">6.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td>  <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost valid" name="tcost[]" readonly=""></td><td><input type="button" class="add btn-success" value="Add More"></td></tr>
                                </tbody></table>

In the above table array values are insert into single row, PRODUCT NAME are separated with comma(,) same as QTY, RATE and TOTAL, can you suggest me. Table structure: S.NO Product Name Qty Rate ($) Total ($)
1. flowers 5 5 35
2. jasmine 6 5 30 3. rose 10 8 80 4. marigold 15 9 135 6.

4
  • each row insert into table means need more memory, so i need to insert an one customer bill in a single row with all values separated by comma - then don't use a relational database but a flat file. But as long as you use MySQL and don't have specific needs that you can show with precise measurements ...just create normalized tables. Commented Feb 18, 2015 at 9:56
  • ok, i'm fresher, no idea about this, Commented Feb 18, 2015 at 10:23
  • I suggest you start learning about SQL JOINs. w3schools is often not considered a good canonical source to link to here on SO, but I don't have a better one right now ...and I think it's not particular bad on the basics of joins, so here's the link: w3schools.com/sql/sql_join.asp Commented Feb 18, 2015 at 10:26
  • possible duplicate of how to store array values into single cell in mysql table using php? Commented Feb 21, 2015 at 7:36

1 Answer 1

-1

This is example one , i tried this code work fine.

<?php
include 'connection/db_connection.php';
if(isset($_REQUEST['save'])) {
$product_name = implode(",", $_REQUEST["product"]);
print $product_name;
}
$query="insert into product (product_name) values('".$product_name."')";
$sql=mysql_query($query);
if($sql) 
echo "success";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form name="myform" method="post">
<input type="text" name="product[]" value="rose">
<input type="text" name="product[]" value="garlands">
<input type="text" name="product[]" value="marigold">
<input type="text" name="product[]" value="jasmine">
<input type="text" name="product[]" value="jasmine garlands">
<input type="submit" name="save" value="Save">
</form>

</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.