mercredi 6 mai 2015

SELECT, UPDATE records using php and mysql

I have a php file that displays records from a mysql db into a html table. For each row I have a check-box added. I would like to select a check box for a given row and UPDATE a field for that row only. I know that an UPDATE statement has to be created then on SUBMIT the UPDATE will process. I have researched but have no idea what to do next.

Here is what I have

$sql = "SELECT * , date_format(created_at, '%m/%d/%y'), time_format(created_at, '%h:%i:%s') FROM `report_facility_maintenance` LEFT JOIN facilities ON  report_facility_maintenance.facility_id = facilities.id ORDER BY created_at DESC";
$result = $conn->query($sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row

       // while($row = $result->fetch_assoc()) {
       echo "<table border=1, width=900px; >
            <tr>
            <th width=300px>Request Information</th>
            <th>Details</th>
            <th>Complete</th>
            </tr>";
       while ($row = mysqli_fetch_assoc($result)) {

        echo "<tr>";
            echo "<td align=Left> <br> <strong>Location: </strong>" . $row["name"]. 
            " <br> <strong>Type: </strong>" . $row["maint_type"]. 
            " <br> <strong>Date: </strong>" . $row["date_format(created_at, '%m/%d/%y')"].
            " <br> <strong>Time: </strong>" . $row["time_format(created_at, '%h:%i:%s')"].
            "<br><strong>Submitted By: </strong>". $row["submitted_by"]. 
            "<br><br></td><td>".$row["details"]. "</td><td><input type=checkbox name=completed[] value=complete /></td>";
            echo "</tr>";
             //print_r($row);
            // echo $result;
        }
        echo "</table><br />";
    } else {
    //echo "0 results";
    }
echo "<input type=submit name=completedSubmit value= Clear&nbsp;Selected />";

$conn->close();
?>

Aucun commentaire:

Enregistrer un commentaire