0

Hi All,
I'm working on a website page that is displaying data from a SQL database. I have a series of echo statements display the data within a table:

echo "<table border '1' bordercolor='#333333' cellpadding='3' cellspacing='0' width='100%'>
<tr>
<th><span class='heading'>ID</span></th>
<th><span class='heading'>Date Submitted</span></th><th><span class='heading'>Location</span></th><th><span class='heading'>Type</span></th><th><span class='heading'>Request</span></th>
<th><span class='heading'>Start Date</span></th><th><span class='heading'>Ad Size</span></th><th><span class='heading'>Color/BW</span></th><th><span class='heading'>Deadline</span></th><th><span class='heading'>Shown Where?</span></th><th><span class='heading'>Run Dates</span></th><th><span class='heading'>Email Ad To:</span></th><th><span class='heading'>Approve</span></th><th><span class='heading'>Comple</span></th>
</tr>";

while($row = mysql_fetch_assoc($result))   
{ 
echo "<tr>"; 
echo "<td>" . $row['order_num'] . "</td>";
echo "<td>" . $row['datetime'] . "</td>"; 
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td width='250px'>" . $row['request'] . "</td>";
echo "<td>" . $row['start'] . "</td>";
echo "<td>" . $row['size'] . "</td>"; 
echo "<td>" . $row['color'] . "</td>";
echo "<td>" . $row['deadline'] . "</td>";
echo "<td>" . $row['shown'] . "</td>";
echo "<td>" . $row['appear'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['approve'] . "</td>";
echo "<td>" . $row['complete'] . "</td>";
} 
echo "</table>";

:

What I would like to do is provide an added function that will allow the manager to approve the order by adding a submit button that will call for the "order_num" of that table row and enter a hidden value into the "approve" field of the database. I've tried to accomplish this a couple of different ways, but all failed misurably.

Thanks in advance for any help that you can offer.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by weekendrockstar
0

One thing that I do to help me when writing out HTML that the PHP processor puts out is after the WHILE statement but before you print anything out I convert to easier variables:

$order_number = $row['order_num'];
$datetime = $row['datetime'];
$location = $row['location'];
etc...

I am not sure what others' takes on this would be as it adds an extra step to the processor but it removes having to use concat (.) in the echo statements to include the values of the fields from the database row. Just personal preference. So my code below will do it my way but you can alter it to make it like the echo statements you have above. Add something like this at the end of the WHILE statement. This will make each row have a button to click to approve that order.

echo '
<td>
 <form action="your_script.php" method=POST>
  <input type=hidden name=order_number value="$order_number">
  <input type=hidden name=approve value="yes">
   <input type=submit value="Approve">
 </form>
</td>
';

What I might do at the top of your page would be to find out if approval is being given to an order when the script loads:

$approval = $_POST['approval']; // You know that post is used for this request
$order_number = $_POST['order_number'];
if ($approval == "yes") { approval(); }

Then you need to write the function called approval where you would probably want to update the specific row with the index of $order_number to print whatever string you want in the approved field to signify that the specific order has been approved which could be "yes" or "approved".

I would put the IF statement regarding approval before the script prints out the data because if you are approving an order it will make the chances to the database and when the page reloads it SHOULD reflect the new change that you made and should show that the order has been approved.

Finally you could use a nested IF conditional statement before the form code I'd shown above so that it will show the button only if the database says that that particular order number has not been approved yet. You don't want buttons to show up even after someone has approved them. That TD would just be empty in the table.

Please let me know if this wasn't what you were looking for and I'll see what I can do.

Edited by weekendrockstar: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.