0

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.

2
  • you can use ajax to send back the status to backend and run sql query there. Commented Oct 1, 2013 at 10:49
  • You should search for tutorial on ajax Commented Oct 1, 2013 at 10:49

2 Answers 2

1

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');
Sign up to request clarification or add additional context in comments.

1 Comment

after updating most probably you need to redirect to listing page
0

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 } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.