Reputation: 836
please view the following code.
<?php foreach($rows as $row): ?>
<tr>
<td><?php echo htmlentities($row['username'], ENT_QUOTES, 'UTF-8');?></td>
<td><?php echo htmlentities($row['id'], ENT_QUOTES, 'UTF-8');?></td>
<td><?php echo htmlentities($row['starthol'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlentities($row['endhol'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlentities($row['days'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><a href="#">Approve</a></td>
<td><a href="*">Reject</a></td>
</tr>
This populate a table from a previously ran sql query. Basically, when approve is clicked,I want to run an SQL query that uses the id of the the row and updates a column in the table called "active".
UPDATE holidays
SET active = "active"
WHERE holid = getid
Any advice on how to do this?
I am a php novice, so please go easy on me. Thank you.
Upvotes: 0
Views: 102
Reputation: 14263
You should consider learning how to GET and POST
<td><a href="active.php?id=?"<?php echo $row['id']; ?> >Approve</a></td>
Server side code active.php(sample dont copy paste you must use post
to update db state not get
also mysql_* depricated)
$id = mysql_real_escape_string($_GET['id']);
mysql_query("UPDATE holidays
SET active = 'active'
WHERE holid = $id")or die(mysql_error());
header('location:listingpage.php?msg=approved');
Upvotes: 1
Reputation: 1375
Are you able to get your query to run and return data? Assuming you have data, you will want to update your foreach()
loop. If you want the loop to work over more than one line, you'll have to use curly braces ({ }
)
So your code would look more like:
<?php foreach($rows as $row) { ?>
...
<?php } ?>
Upvotes: 0