I need some advice on my script. I am developing a roll call system, and I want to get out of a bad habit of mine.
Here is a pic of what I want: http://i.stack.imgur.com/UdqMQ.png
Specifically, the buttons above each of the day columns. Each of these buttons do nearly the same thing, but for different dates in my SQL database.
So here is the code I have:
Inputs:
<th><input type='submit' id='mAllR' name='mAllR' value='All Attended'></th>
<th><input type='submit' id='tAllR' name='tAllR' value='All Attended'></th>
<th><input type='submit' id='wAllR' name='wAllR' value='All Attended'></th>
<th><input type='submit' id='tAllR' name='tAllR' value='All Attended'></th>
<th><input type='submit' id='fAllR' name='fAllR' value='All Attended'></th>
As you can see, its basically each button having its own ID which will call a function by its name.
This would be fine by me if there were only 5 input buttons, which there are in my example, but there are 7 departments, which means 35 buttons. I do not want to make 35 functions that do ALMOST the same thing.
The code I have to work with that I can adapt is below:
if(isset($_POST['mAllR']))
{
$index = 0;
foreach($_POST as $key => $value)
{
while($index < $_SESSION['amountT'])
{
$index++;
$sql = ("UPDATE `Employee` SET `Monday`='Attended' WHERE `Job`='Remarketing'");
mysqli_query($con, $sql);
}
}
if($sql)
{
mysqli_close($con);
sleep(4);
echo '<meta http-equiv="refresh" content="0">';
}
}
Each button, the way it is now, will needs its own version of this. (Do not worry about the sessions ETC, those are handled elsewhere to avoid overlapping/underlapping.
So really, the code is not the issue, I just want to optimize this into less code. Any suggestions are welcome.