Jump to content

Display data beside select option after option selected


newphpcoder

Recommended Posts

Hi..

 

I have a select option where the data came from database and I use php codes for displaying the data to select option. And it works, now I need to display bin_loc base on what lot_number that I choose.

 

 

I want to happen is after I choose lot number the bin_loc for that lot_number will also displayed.

here is my code in displaying lot_number:

 

$query = "SELECT lot_number from wms WHERE (date_shelve IS NOT NULL) AND stock_item = '$ItemCode' AND (qty = orig_qty OR qty != '0.00') AND qty >= '$SubQty' ORDER BY qty";                 
$rows = mysql_query($query, $con); 
echo "<td><select name = 'lot_number' id='lot_number'>";
echo "<option></option>";                
  while ($record = mysql_fetch_array($rows))          
  {             
      echo "<option value = '{$record['lot_number']}'";             
      if ($lot_number == $record['lot_number'])                 
      echo "selected = 'selected'";             
       echo ">{$record['lot_number']}</option>";        
  }         
  echo "</select>";
  echo "</td>";

 

now I need to display bin_loc in <td></td> after the lot_number;

 

I tried this:

$sql = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'";

 

but it did not work cause I can get the value of option that I selected.

 

I hope someone can Help in automatically displaying bin_loc.

 

Thank you so much

Link to comment
Share on other sites

how can I do that?can you give me a example:

 

 

here is my whole code:

 

<?php 
    session_start();                                                                         
   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>
<title>Picking</title>
<head>
<link href="kanban.css" rel="stylesheet" type="text/css">


<script type="text/javascript">
function getText(){
    var x=document.getElementById("lot_number")
    //alert(x.options[x.selectedIndex].text);
   var lot_number = (x.options[x.selectedIndex].text); 
   
   document.picking_form.action="PickingForm.php?lot_number="+lot_number;
    document.picking_form.submit();
    
}
</script>

</head>
<body> 


<?php
$Approved = isset($_POST['priority']);
if ($Approved)
{
    $lot_number = $_POST['lot_number'];
    $sr_num_ = $_POST['sr_num_'];
    $SubQty = $_POST['SubQty'];
    $ItemCode = $_POST['ItemCode'];
    $picked_by = $_POST['picked_by'];
    $date_pick = $_POST['date_pick'];

$sql = "SELECT stock_item, qty FROM wms WHERE stock_item = '" . $ItemCode . "' AND lot_number = '" . $lot_number . "'"; 
$res = mysql_query($sql, $con) or die( "Query : [$sql]<br/>\nError : ". mysql_error($con));

$row = mysql_fetch_assoc($res);

$stock_item = $row['stock_item'];
$qty = $row['qty'];

if($qty >= $SubQty){

$output = $qty - $SubQty;

$qty_withdraw = '0.00';
}
else{
$output = '0.00';
$qty_withdraw = $SubQty - $qty;
}     


$sql_up = "UPDATE wms SET qty = '$output', sr_number = '$sr_num_', picked_by = '$picked_by', qty_withdraw = '$qty_withdraw', date_pick = '$date_pick'
WHERE lot_number = '$lot_number' AND stock_item = '$ItemCode'";
//echo $sql_up;
//exit;
$res_up = mysql_query($sql_up, $con) or die( "Query : [$sql_up]<br/>\nError : ". mysql_error($con));
    
}
else{
    
}

?>

  <div id="SR_date">
<label>Date :</label>
<input type="text" name="date_pick" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;">    
</div>

<div id="Picking">
<!--<label class="LLabellot">Select SR # :</label>-->
<?php          
  $sr_num_ = $_POST['sr_num_'];

  
$sql = "SELECT sr_number, Items, DemandedQty, uom 
FROM sr_main WHERE sr_number = '$sr_num_'";
$res_sr_main = mysql_query($sql, $con);



$row_num = mysql_num_rows($res_sr_main);

if($row_num > 0){

while($row_sr_main = mysql_fetch_assoc($res_sr_main)){

$sr_number_ = $row_sr_main['sr_number'];
$items = $row_sr_main['Items'];
$demandedqty = $row_sr_main['DemandedQty'];
$uom = $row_sr_main['uom'];  
echo "<label> SR # :</label>";
echo "<input type='text' readonly='readonly' style='border:none;' id='sr_number_' name='sr_number_' value='$sr_number_'>";

echo "<table>";
echo "<th>Items</th>
        <th> Item Code </th>
        <th> Demanded Qty </th>
        <th> UoM </th>
        <th> Description </th>
        <th> Lot Number </th>
        <th> Bin Location </th>
        <th> Picked By </th>
        <th> Approved</th>";
echo "<tr>
        <td>$items</td>
        <td></td>
        <td style='text-align:right;'>$demandedqty</td>
        <td>$uom</td>
        </tr>";             
        
$sql_sub = "SELECT s.sr_number, s.Items, s.ItemCode, s.SubQty, s.UoM, s.Description 
FROM sr_submain s WHERE s.sr_number = '$sr_num_' and s.Items = '$items' AND NOT EXISTS(SELECT w.stock_item FROM wms w WHERE s.ItemCode = w.stock_item AND w.sr_number = s.sr_number AND (w.qty_withdraw !='0.00' OR w.qty_withdraw = 'NULL'))";

$res_sub = mysql_query($sql_sub, $con); 
while($row_sub = mysql_fetch_assoc($res_sub)){
  echo "<form name='picking_lotnum' action='PickingForm.php?sr_num_=".$sr_num_."' method='POST'>";
  
  $sr_num = $row_sub['sr_number'];
  $Items = $row_sub['Items'];
  $ItemCode = $row_sub['ItemCode'];
  $SubQty = $row_sub['SubQty'];
  $UoM = $row_sub['UoM'];
  $Description = $row_sub['Description'];

$query = "SELECT lot_number from wms WHERE (date_shelve IS NOT NULL) AND stock_item = '$ItemCode' AND (qty = orig_qty OR qty != '0.00') AND qty >= '$SubQty' ORDER BY qty";                 
$rows = mysql_query($query, $con); 

echo "<tr>
        <td></td>
        <td><input type='text' name='ItemCode' id='ItemCode' value='$ItemCode' readonly='readonly' style='border:none;font-family: Arial, Helvetica, sans-serif;
    font-size: .9em;'></td>
        <td><input type='text' name='SubQty' id='SubQty' value='$SubQty' readonly = 'readonly' style='border:none; text-align:right;font-family: Arial, Helvetica, sans-serif;
    font-size: .9em;'></td>
        <td>$UoM</td>
        <td>$Description</td>";
                
echo "<td><select name = 'lot_number' id='lot_number'>";
echo "<option></option>";                
  while ($record = mysql_fetch_array($rows))          
  {             
      echo "<option value = '{$record['lot_number']}'";             
      if ($lot_number == $record['lot_number'])                 
      echo "selected = 'selected'";             
       echo ">{$record['lot_number']}</option>";        
  }         
  echo "</select>";
  echo "</td>";
   
$lot_number = $_POST[lot_number]; 

$sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'";
$res_bin = mysql_query($sql_bin);

$row_bin = mysql_fetch_assoc($res_bin);

$bin_loc = $row_bin['bin_loc'];

echo $bin_loc;
   
  echo "<td>$bin_loc</td>";
  //echo "<td>$bin_loc</td>";
  
  echo "<td> <input type='text' name='picked_by' id='picked_by' size='20' value=''> </td>";  
    // echo "<td><input type='checkbox' name='chk_[]' value='$ItemCode' onclick = 'chk();' id='chk_'></td>
     echo "<td><input type='submit' name='priority' value='Approved' id='priority'></td>";

     echo "</tr>";
     echo "<input type='hidden' name='date_pick' value='$Date_Shelve' size='16' style='border: none;'>";           
     echo "<input type='hidden' readonly='readonly' style='border:none;' id='sr_num_' name='sr_num_' value='$sr_number_'>"; 
     echo "</form>"; 
}       
}
}
  echo "</table>"; 
  echo "</div>";     
  ?>
</body>
</html>

 

Thank you so much..

 

I tried this:

 

if(isset($_POST['lot_number']))  {


     $lot_number=mysql_real_escape_string($_POST['lot_number']); 
      echo $lot_number;  
     $sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'";
     
     echo $sql;
     $res_bin  = mysql_query($sql_bin, $con);
     $row_bin = mysql_fetch_assoc($res_bin);
     
     $bin_loc = $row_bin['bin_loc'];
     
     echo $bin_loc;

 

but no output display

 

Thank you

Link to comment
Share on other sites

I don't have the time required to write up the script for you, but you can google AJAX examples far faster then I can write one up! I would suggest using AJAX so that you can do it without refreshing the page with each click, and just refresh the needed data.

Link to comment
Share on other sites

Sure, google is your best friend...

 

http://stackoverflow.com/questions/9604078/how-do-i-populate-a-select-list-in-jquery-with-data-from-php There is a practical walk through on that page that will show you how it's done, but you will need to apply what your learning to your own needs. You'll also notice how the code is broken up into manageable chunks to make the flow easier to read and understand.

 

http://codeassembly.com/Simple-chained-combobox-plugin-for-jQuery/ Taken from the same page this is an easy to follow solution.

 

http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ A 3rd example encase the other two don't work for you.

Link to comment
Share on other sites

Thank you for your suggested links, but sorry, it's a jquery and I also dont have any idea about jquery, my goal today is to resolve this problem that I encountered.

 

Thank you so much.

 

I think my issue is on how can I get using ajax the value of selected option.

 

 

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.