When you access data from a mysql table and use loops to output all rows of data, you can add forms inside each loop which can trap the row values for which they can be tranferred into form hidden fields? Sounds confusing? The code below will show how easy it is to do that.
if (ISSET($_POST[‘submit’])){
$my_id = $_POST[‘myid’];
$myname = $_POST[‘myname’];
echo “My id is “.$my_id.” and my name is “.$myname;
echo “<br/><br/><strong>What just happened?</strong><br/><br/>
We selected the entire rows from the database where the id is less than 3; which are ids 1 and 2. Since there are 2 ids 1 and 2, the loop create 2 results and hence 2 forms. Each result will show a submit button; since other input fields are hidden. Now, when submit is clicked, we could make any query do what we want since we could use the myname and myid post variables. <br/><br/>”;
}
require_once(‘connect.inc’);
$db=public_db_connect();
$command = “SELECT * FROM table_sort where id<3 “;
$result = mysqli_query($db, $command);
while ($row = mysqli_fetch_assoc($result)){
$myid = $row[‘id’];
$name = $row[‘firstname’];
?>
<form method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
<input type=”hidden” name=”myid” value=”<?php echo $myid;?>” />
<input type=”hidden” name=”myname” value=”<?php echo $name; ?>” />
<input type=”submit” name=”submit” value=”Submit Form” />
</form>
<?php
}
?>
© 2018 ALL Rights Reserved | Sitemap
Vancouver | North Vancouver | Burnaby | Richmond | Coquitlam | Port Coquitlam | Surrey | Langley | Maple Ridge | Mission | Abbotsford | Kamloops | Kelowna | Victoria | Squamish | Whistler | Pemberton