Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Why $row['id'] returns 0

I am trying to create an HTML table and populate data from MySQL table using PHP and the HTML table will have an edit column through which I want the user to click on edit and based on it the user is populated with edit form.

I have written the following code

<?php while($rw = mysql_fetch_array($resul)) { ?>
    <tr class="text2" <?php if ($i % 2 == 0){?> bgcolor="#CCCCFF" <?php } ?>>
        <td align="left" ><?php echo $rw['sr_no'];?> </td>
        <td align="left"><?php echo $rw['filling_date'];?></td>
        <td align="center" ><?php echo $rw['source'];?></td>
        <td align="left"><?php echo $rw['name_reporter']; ?></td>
        <td align="center"><?php  echo $rw['sex']; ?>    </td>
        <td align="center" style="font-weight:bold;"><a href="edit_entry_form.php?edit_id=<?php echo $rw['id'] ;?>">Edit</a></td>
    </tr>
<?php $i++; } ?>

This code <a href="edit_entry_form.php?edit_id=<?php echo $rw['id'] ;?>">Edit</a> from the above returns 0.

I am using the following code to fetch data from MySQL

  $sql_in="SELECT n.id,n.sr_no,n.source,n.name_reporter,n.report_month,n.filling_date,n.s_filling_date,
        n.sex,n.age_months,n.weight_kg,n.height_cm,n.pitting_oedema,n.muac_cm,n.currnt_breast_fed,n.bf_hours,n.exclusive_bf,n.comp_feeding,
        n.frequency_cf,n.food_diversity,hf.hf_name, n.ARI,n.Measles, n.VitaminA, n.Diarrhea
        FROM nutrition_data n 
        LEFT OUTER JOIN healthfacilities hf ON n.hfc=hf.hf_code
        WHERE n.filling_date between '".$report_month_frm."' AND '".$report_month_to."' $comm3 $comm2 $comm1";
        //echo $sql_in;exit;
        $i=0;
        $resul = mysql_query($sql_in);
        $rec = mysql_num_rows($resul);

Any solution and fix, please.

Comments