I have a foreach statement which is used to echo an array with 3 variables.
Each time a row in the array is echo’d a checkbox is also echo’d.
I want to use this checkbox to allow the users to delete a particular row, so if they want to delete the third row they will check this box an then hit a submit button (which will be called remove) which will reload this page minus the row they have deleted.
What I can’t get my head around is how do I pass a variable from a checkout to my submit (remove) button code.
Hope someone can help.
/***************** Start of foreach statement ************/
foreach ($_SESSION['grind_array'] as $entry)
{
// Get the number of the grind
$grind_number = $entry['counter'];
// Get the array number
$array_number = $grind_number - 1;
echo"<h4>Grind $grind_number</h4>";
// Query to obtain the interest name
$query_result = mysql_query ("SELECT * FROM interests WHERE id_interest = {$entry['Interest']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_interest = $row[1];
echo"<p class = 'confirmation'>Your interest is $confirmation_interest.</p>";
}
// Query to obtain the subject name
$query_result = mysql_query ("SELECT * FROM subjects WHERE id_subject = {$entry['Subject']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_subject = $row[1];
echo"<p class = 'confirmation'>Your subject is $confirmation_subject.</p>";
}
// Query to obtain the level name
$query_result = mysql_query ("SELECT * FROM levels WHERE id_level = {$entry['Level']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_level = $row[1];
echo"<p class = 'confirmation'>Your have choosen $confirmation_level.</p><br>";
}
/**************** Checkbox **********************/
echo'<p class = "confirmation"><input type="checkbox" name="remove" value="$array_number"/> Remove</p>';
}// End of foreach
/****************If remove is clicked***************/
if (isset($_POST['submit']))
{
unset($_SESSION['grind_array'][$array_number]);
ob_end_clean(); // Delete the buffer
header("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/confirmation.php");
exit();
}
Each time a row in the array is echo’d a checkbox is also echo’d.
I want to use this checkbox to allow the users to delete a particular row, so if they want to delete the third row they will check this box an then hit a submit button (which will be called remove) which will reload this page minus the row they have deleted.
What I can’t get my head around is how do I pass a variable from a checkout to my submit (remove) button code.
Hope someone can help.
/***************** Start of foreach statement ************/
foreach ($_SESSION['grind_array'] as $entry)
{
// Get the number of the grind
$grind_number = $entry['counter'];
// Get the array number
$array_number = $grind_number - 1;
echo"<h4>Grind $grind_number</h4>";
// Query to obtain the interest name
$query_result = mysql_query ("SELECT * FROM interests WHERE id_interest = {$entry['Interest']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_interest = $row[1];
echo"<p class = 'confirmation'>Your interest is $confirmation_interest.</p>";
}
// Query to obtain the subject name
$query_result = mysql_query ("SELECT * FROM subjects WHERE id_subject = {$entry['Subject']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_subject = $row[1];
echo"<p class = 'confirmation'>Your subject is $confirmation_subject.</p>";
}
// Query to obtain the level name
$query_result = mysql_query ("SELECT * FROM levels WHERE id_level = {$entry['Level']}");
while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))
{
$confirmation_level = $row[1];
echo"<p class = 'confirmation'>Your have choosen $confirmation_level.</p><br>";
}
/**************** Checkbox **********************/
echo'<p class = "confirmation"><input type="checkbox" name="remove" value="$array_number"/> Remove</p>';
}// End of foreach
/****************If remove is clicked***************/
if (isset($_POST['submit']))
{
unset($_SESSION['grind_array'][$array_number]);
ob_end_clean(); // Delete the buffer
header("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/confirmation.php");
exit();
}