Jump to content

Approve button inside while loop


newphpcoder

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.