Php: problem in checkbox array?
-
I made an array that take the cost stored in checkbox array and then added the value of the cost to the variable $sum, the problem is the array leave the first cell which ix $checkbox[0] empty and start fill the array from $checkbox[1], I dont know why?? I checked the code thousand times but nothing seemed wrong to me here is the code: <? mysql_select_db($database_connect, $connect); $query_product = "SELECT * FROM vtiger_product_spec WHERE productid = '$abc'"; $product = mysql_query($query_product, $connect) or die(mysql_error()); $row_product = mysql_fetch_assoc($product); $totalRows_product = mysql_num_rows($product); ?> <table> <? $sum=0; do{ ?> <tr><td> <input type="checkbox" name="pro[]" value="<? echo $cost;?>"/> <? echo ($row_product['name']); ?> </td> <td> <? echo $cost=$row_product['cost'];?> </td></tr> <? }while($row_product = mysql_fetch_assoc($product)); if(isset($_POST['Submit'])){ $pro=$_POST['pro']; $how_many = count($pro); for ($i=0; $i<$how_many; $i++) { echo $sum=$sum+$pro[$i]; } } ?> </table>
-
Answer:
comment out the first call to mysql_fetch_assoc(). The cursor is at the second array element when the program enters the while loop.
cutegirl... at Yahoo! Answers Visit the source
Related Q & A:
- How to pass javascript jQuery variable value in php array?Best solution by Stack Overflow
- How to post an array of complex objects (that has an array of complex objects) with jQuery?Best solution by Stack Overflow
- How to parse inner array in JSON response with PHP?Best solution by Stack Overflow
- how can i remove an array from an array?Best solution by Stack Overflow
- how to insert multiple rows from MySQL with checkbox?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.