stirrah Posted November 26, 2013 Share Posted November 26, 2013 Hey! How should I do if I want to populate a table with results from DB, and then make a submit button beside each row..and then make a query depending on the values of that row. This is my code right now: if (isset($_POST['submit'])){ // do some query to the db depending on row } ?> <h2>Accept or decline your invitation:</h2> <?php $my_id = $user_data['user_id']; $query = mysql_query(MY QUERY) ?> <table class='display'> <th>ID</th> <th>Namn</th> <th>Inbjuden av</th> <th>Svara</th> <?php while($row = mysql_fetch_assoc($query)) { ?> <tr> <td><?php echo "<a href='project.php?pid=" . $row['projectId'] . "'>" . $row['projectId'] . "</a>"; ?></td> <td><?php echo $row['projektName'] ?></td> <td><?php echo $row['username'] ?></td> <td><form action="" method="POST"><input type="submit" name="submit" value="Accept!"></form></td> </tr> <?php } ?> Problem with this setup is that it will submit all the rows before aswell.. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 27, 2013 Share Posted November 27, 2013 To accept a specific database entry, the form needs to be updated to pass that entry's ID. If you want to stick with HTML forms, you could add the ID to a hidden field. If you're not familiar with creating hidden fields, perhaps the following will help: http://www.tizag.com/htmlT/htmlhidden.php Note that you could also use an HTML link. For example, you could try something like this: <td><?php echo "<a href='?accept=" . $row['projectId'] . "'>Accept</a>"; ?></td> Just keep in mind that the information passed through links are GET variables. So you would need to use $_GET. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.