mardi 28 juin 2016

How can I create a query to input rows without repeating the same syntax?

I am making an attendance taker for my school. I was going over the suggestions to my last multi question I was given code suggestions such as

INSERT INTO attendence  (FName, LName, Mark)
SELECT  'FName1', 'LName1', 1
UNION ALL
SELECT  'FName2', 'LName2', 2
UNION ALL
SELECT  'FName3', 'LName3', 3

or

INSERT INTO attendence  (FName, LName, Mark)
$FName, $LName, $Mark

However, these suggestions limit me in only allowing me to insert as many rows as I have coded in. Because my form calls on the names of the students from the table there could be more and more names added each day. I don't want to keep on adding in more lines into my select statement. What sql statement will allow me to input a lot of rows.

<?php

if(isset($_POST['search']))
{
    $valueToSearch = $_POST['valueToSearch'];
    // search in all table columns
    // using concat mysql function
    $query = "SELECT * FROM `records` WHERE CONCAT(`FName`, `LName`) LIKE '%".$valueToSearch."%'";
    $search_result = filterTable($query);

}
 else {
    $query = "SELECT * FROM `records`";
    $search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
    $connect = mysqli_connect("host", "user", "password", "database");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}

?>
<form action="submit.php"method="post">
<table border="1" align="center">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Mark</th>

</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td>
<input type="text" name="FName" value="<?php echo $row['FName']?>"/>
</td>
<td>
<input type="text" name="LName" value="<?php echo $row['LName']?>"/>
</td>
<td>
<select name="Mark" id="Mark">
<option value="Present">Present</option>
<option value="Tardy">Tardy</option>
<option value="Absent">Absent</option>
</select>
</td>

<table align="center">
            <tr>
                <td>
                <input type="submit" value="Submit" >
                </td>
            </tr>

        </table>

        </table>
    </table>
    </form>

Aucun commentaire:

Enregistrer un commentaire