newphpcoder Posted April 19, 2012 Share Posted April 19, 2012 Hi... I have form which data is inside while loop and per row has a approved button, Now I have no idea that when I click the approve button the JO # from that row will display and save to the database. here is my code and sample form. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Sales Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <form name="loading_kanban" action="" method="post"> <div id="SR_date"> <label>Date :</label> <input type="text" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="kanban_table"> <table> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Requirements </th> <th> Priority</th> <?php $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order"; $res_so = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_so)){ $ETD = $row['ETD']; $PO_No = $row['PO_No']; $SKUCode = $row['SKUCode']; $Description = $row['Description']; $POReq = $row['POReq']; echo "<tr> <td> </td> <td>$ETD</td> <td>$PO_No</td> <td>$SKUCode</td> <td>$Description</td> <td>$POReq</td> <td> </td> <td><input type='button' name='priority' value='Approved' id='priority'></td> </tr>"; } ?> </table> </div> </form> </body> </html> 18135_.doc Quote Link to comment https://forums.phpfreaks.com/topic/261235-approve-button-inside-while-loop/ Share on other sites More sharing options...
blacknight Posted April 19, 2012 Share Posted April 19, 2012 we dont dl attachements post the code in ]code] brackets but you most likely need to name each button with its own id and pot it in its own form but you can use checkboxes and approve them that way Quote Link to comment https://forums.phpfreaks.com/topic/261235-approve-button-inside-while-loop/#findComment-1338812 Share on other sites More sharing options...
Psycho Posted April 19, 2012 Share Posted April 19, 2012 I would create each submit button as a separate form. Then you can include a hidden field in each form with the value of the ID you need to pass Quote Link to comment https://forums.phpfreaks.com/topic/261235-approve-button-inside-while-loop/#findComment-1338814 Share on other sites More sharing options...
Psycho Posted April 19, 2012 Share Posted April 19, 2012 Here's some sample code. I corrected some problems in your code (e.g. no TR tags around the header row) and moves some logic around to be more organized. You don't show the JO code anywhere in your code, so I just put a placeholder in the value parameter for the hidden field. Also, you will probably want to modify the default margins/padding for form tags else they rows may not display as you wish. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { die('failed'); } mysql_select_db("mes", $con); $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order"; $res_so = mysql_query($sql, $con); $recordsHTML = ''; while($row = mysql_fetch_assoc($res_so)) { $recordsHTML .= "<tr> <td> </td> <td>{$row['ETD']}</td> <td>{$row['PO_No']}</td> <td>{$row['SKUCode']}</td> <td>{$row['Description']}</td> <td>{$row['POReq']}</td> <td> </td> <td> <form name='loading_kanban' action='' method='post'> <input type='hidden' name='jo_num' value='{JO_VALUE_GOES_HERE}'> <input type='button' name='priority' value='Approved' id='priority'> </form> </td> </tr>"; } $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Sales Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <div id="SR_date"> <label>Date :</label> <input type="text" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="kanban_table"> <table> <tr> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Requirements </th> <th> Priority</th> </tr> <?php echo $recordsHTML; ?> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/261235-approve-button-inside-while-loop/#findComment-1338820 Share on other sites More sharing options...
newphpcoder Posted April 20, 2012 Author Share Posted April 20, 2012 Thank you.. my problem now is on displaying JO Number. I want to happen is it will only display after I click the approved button. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Job Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <div id="SR_date"> <label>Date :</label> <input type="text" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="kanban_table"> <table width="auto"> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Requirements </th> <th> Priority</th> <?php $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order"; $res_so = mysql_query($sql, $con); $Approved = isset($_POST['priority']); if ($Approved) { $PO_No = $_POST['PO_No']; //----I want to display only the jo_number after click the approved button and it only display on the row where I click the approved button--- $sql = "SELECT jo_number FROM job_order ORDER BY jo_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //---------------------------------------- $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['jo_number'],0,3)); $currentSRYear = (int)(substr($row['jo_number'],2,2)); $currentSRMonth = (int)(substr($row['jo_number'],0,2)); $currentSRNum = (int)(substr($row['jo_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); //JO_No } while($row = mysql_fetch_assoc($res_so)){ echo "<form name='joborder_form' action='' method='post'>"; $PO_No = $row['PO_No']; echo "<tr> <td><input type='text' name='JO_No' id='JO_No' value='$currentSR' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='ETD' id='ETD' value='$row[ETD]' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='PO_No' id='PO_No' value='$row[PO_No]' style='border:none;' size='30'></td> <td><input type='text' name='SKUCode' id='SKUCode' value='$row[sKUCode]' style='border:none;' size='15'></td> <td><input type='text' name='Description' id='Description' value='$row[Description]' style='border:none;' size='35'></td> <td><input type='text' name='POReq' id='POReq' value='$row[POReq]' style='border:none;width:auto;' size='10'></td> <td> </td> <td><input type='submit' name='priority' value='Approved' id='priority'></td> </tr>"; echo "</form>"; } ?> </table> </div> </body> </html> Thank you Thank you Quote Link to comment https://forums.phpfreaks.com/topic/261235-approve-button-inside-while-loop/#findComment-1338940 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.