samedi 23 avril 2016

How can i echo data to checkbox field using JQuery Mobile and php?

In viewsessions.php, I am attempting to select multiple values from a db and insert it into grouped checkbox fields (eg. typeofactivity, employer, date, time, amount as one single checkbox field) using <input type="checkbox" name="example" id="example"> or similar in JQuery mobile, so that when displayed on the hmtl page, various checkboxes can be selected to send to another page. So far, i have managed to display the contents of the db using a table, but can't find a working solution to display the data in checkboxes?

Any ideas greatly appreciated! :)

Code so far: viewsessions.php

<?php

$servername = "localhost";
$username = "root";
$password = "cornwall";

$con=mysqli_connect('localhost','root','cornwall','ibill');
// This code creates a connection to the MySQL database in PHPMyAdmin named 'ibill':

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// The connection is then checked, if it fails, an echo is sent back to the page stating a connection error.

$viewsessions = "SELECT typeofactivity, employer, date, time, amount FROM session_details";
$result = $con->query($viewsessions);

if ($result->num_rows > 0) {
    echo "<table><tr>
                    <th>Type of Activity</th>
                    <th>Employer</th>
                    <th>Date</th>
                    <th>Time</th>
                    <th>Amount (GBP)</th>
                </tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr>
                <td>".$row["typeofactivity"]."</td>
                <td>".$row["employer"]."</td>
                <td>".$row["date"]."</td>
                <td>".$row["time"]."</td>
                <td>".$row["amount"]."</td>
            </tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}
$con->close();
?>




Aucun commentaire:

Enregistrer un commentaire