How can I construct the array problem?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.