evios Posted March 21, 2008 Share Posted March 21, 2008 Hi there, i am currently working on php for a form claim. And in database, i have a table which is use to store each input entered by the user (so it will increase each time user entered once). Then the database is accessible by admin. I juz want to add a radio button for approval or delete for the looping. below will be my code: $result = mysql_query($query) or die(mysql_error()); echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"; echo "<center><b>Welcome to the Administrator page</b></center>"; echo "<br />"; echo "<center>Below will be a list of users with the claims pending for approval..."; echo "<br />"; echo "<br />"; echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Username</th>"; echo "<th>password</th>"; echo "<th>department</th>"; echo "<th>duemonth</th>"; echo "<th>category</th>"; echo "<th>amount</th>"; echo "<th>specification</th>"; echo "<th>approve</th>"; echo "<th>delete</th></tr>"; // Print out the contents of each row into a table while($row = mysql_fetch_array($result)){ echo "<tr><td>"; echo $row['username']; echo "</td><td>"; echo $row['password']; echo "</td><td>"; echo $row['department']; echo "</td><td>"; echo $row['duemonth']; echo "</td><td>"; echo $row['category']; echo "</td><td>"; echo $row['amount']; echo "</td><td>"; echo $row['specification']; echo "</td><td>"; echo "</td><td>"; echo "<br />"; //here, i need to add the button for each loop and identifier to differentiate the appropriate row so that the data can be saved as another variables or array. } Link to comment https://forums.phpfreaks.com/topic/97191-approve-and-delete-data/ Share on other sites More sharing options...
dare87 Posted March 21, 2008 Share Posted March 21, 2008 This is how I do it. <?php // Connect to the database. require_once ('mysql_connect.php'); // Make the query. $query = "SELECT BLAH, BLAH, BLAH, DATE_FORMAT(date_entered, '%M %d, %Y') AS date FROM database WHERE approved=0 ORDER BY date_entered ASC"; // Run the query. $results = @mysql_query ($query); $numOfRecords = mysql_num_rows($results); // If the query ran w/o error & came up with records, display them. if ($numOfRecords > 0) { // Table header. echo ' <table align="left" cellspacing="0" cellpadding="5"> <tr> <td align="left"> </td> <td align="left"><b>Approve</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b>BLAH</b></td> <td align="left"><b>BLAH</b></td> <td align="left"><b>BLAH</b></td> <td align="left"><b>Date Submitted</b></td> </tr>'; // Fetch and print all the records. $bg = '#dee4ed'; // Set the background color. $count = 0; // Variable to name the results in order. // Start the form. echo '<form action="date_approve.php" method="post">'; while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) { // Alternate the background color. $bg = ($bg == '#dee4ed' ? '#ffffff' : '#dee4ed'); echo ' <tr bgcolor="' . $bg . '"> <td align="left"><a href="edit.php?title=' . $row['BLAH'] . '&name=' . $row['BLAH'] . '&rating=' . $row['BLAH'] . '">Edit</a></td> <td align="center"><input type="radio" name="result' . $count . '" value="approve"></td> <td align="center"><input type="radio" name="result' . $count . '" value="delete"><input type="hidden" name="rating' . $count . '" value="' . $row['BLAH'] .'"></td> <td align="left">' . $row['BLAH'] . '</td> <td align="left">' . $row['BLAH'] . '</td> <td align="left">' . $row['BLAH'] . '</td> <td align="left">' . $row['BLAH'] . '</td> </tr>'; // Increment count. $count++; } // Create submit/reset, close the tabble, close the form. echo ' <tr bgcolor="#ffffff"> <td align="left"><input type="submit" class="button" name="submit" value="Submit"></td> <td align="left"><input type="reset" class="button" name="reset" value="Reset"></td> </tr> </table>'; echo '</form>'; // Free up the resources. mysql_free_result ($results); } else echo '<p>There are no items that need to be approved at this time.</p>'; // This will control the review quotes form. if (isset($_POST['submit'])) { // Loop through the radio buttons. for ($i = 0; $i <= $count; $i++) { // If the radio buttons was clicked, determine approve/delete and operate accordingly. if (isset($_REQUEST['result' . $i])) { $result = $_REQUEST['result' . $i]; $userrating = $_REQUEST['userrating' . $i]; // Create an array to store the approved. $approvedDates = array(); if ($result == 'approve') { // Set up the query. $query = "UPDATE database SET approved=1 WHERE rating=$rating"; // Run the query. $results = @mysql_query ($query); } else if ($result == 'delete') { // Set up the query. $query = "DELETE FROM database WHERE rating=$rating"; // Run the query. $results = @mysql_query ($query); } } } // Delete the output buffer. ob_end_clean(); // Reload the page. $url = approve.php'; header("Location: $url"); } ?> This is just an example Link to comment https://forums.phpfreaks.com/topic/97191-approve-and-delete-data/#findComment-497327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.