i have html form which has multiple textarea , values coming database.
while($row=mysql_fetch_array($record)){ echo "<tr class='item-row'>"; echo "<td>" .$startsrno. "</td>"; echo "<td class='item-name'> <div class='delete-wpr'><textarea name='productname[]'>".$row['name']."</textarea></div></td>"; echo "<td>".$row['pkgsize']."</td>"; echo "<td><textarea class='savings' name='saving[]'>".$row['savings']."</textarea></td>"; echo "<td><textarea class='mrp' name='mrp[]'>".$row['mrp']."</textarea></td>"; echo "<td><textarea class='qty' name='qty[]'>1</textarea></td>"; echo "<td><textarea class='cost' name='saleprice[]'>".$row['saleprice']."</textarea></td>"; echo "<td><textarea class='price' name='total[]'>".$row['saleprice'] * '1'."</textarea></td>"; echo '<input type="hidden" name="productid[]" value="'.$row['id']. '">'; echo '<input type="hidden" name="pkgsize[]" value="'.$row['pkgsize']. '">'; echo "</tr>"; $startsrno++; }
now when submit form these arrays of form has multiple values in column format need in row form:
by doing (using implode function ()) below output:
$id = implode(',',$_post['productid']);<br/> $name = implode(',',$_post['productname']); $saving = implode(',',$_post['saving']); $qty = implode(',',$_post['qty']); $pkgsize = implode(',',$_post['pkgsize']); $mrp = implode(',',$_post['mrp']); $saleprice = implode(',',$_post['saleprice']); $total = implode(',',$_post['total']);
current output using echo e.g. echo $name == (boost,olay):
boost,olay,bournvita (name) 45,35,20 (savings) 2,3,5 (qty) 500gm,20ml,1kg(pkgsize) 120,70,320(mrp) 75,35,300(saleprice) 150,105,1500(total)
but want output in below stated (row) format use directly in insert query:
(boost,45,2,500gm,120,75,150),(olay,35,3,20ml,120,35,105),(bournvita,20,5,1kg,300,75,1500)
thanks in advance
sounds need for-loop that. provided validated data , made sure no empty 'cell' passed in.
$products = '(' . $name[0] . ',' . $saving[0] . ',' . $qty[0] . ',' . $pkgsize[0] . ',' . $mrp[0] . ',' . $saleprice[0] . ',' . $total[0] . ')'; for($i = 1; $i < count($id); $i++) $products = ',(' . $name[i] . ',' . $saving[i] . ',' . $qty[i] . ',' . $pkgsize[i] . ',' . $mrp[i] . ',' . $saleprice[i] . ',' . $total[i] . ')';
my php skills may not date , done better, i'd should work.
Comments
Post a Comment