dqingn8836 2014-01-17 06:35
浏览 28
已采纳

如何使用php mysql基于下拉选择更新其他字段

I have a table where i store item id and its description. now i am displaying them as dropdown menu from mysql. here is table

stock_id            description
2013_1Mess_Jan  Canteen
2013_Mess_August    Canteen
2013_Mess_Dec   Canteen
2013_Mess_July  Canteen
2013_Mess_Nov   Canteen
2013_Mess_Oct   Canteen
2013_Mess_Sep   Canteen
A4_Sheets           Stationary
Aloo_Parantha   Canteen
BBA11_4th_sem   Fine
Biscuit_02          Canteen
Biscuit_05          Canteen
Biscuit_10  c      Canteen
Black_White PrintOut
Book_Lost   Library
BP_BBA12_2nd    FIne
BP_PGDM_11  FIne
BP_PGDM_12  FIne

now i want if i select stock_id then description will automatically show its discription. here stock is is unique key. here is my code ( i know it is possible with ajax but i am zero with it)

<?php
$con = mysql_connect("localhost","root","");
 $db = mysql_select_db("ex_smartcard2013",$con);

 $getitem=mysql_query("SELECT * FROM 0_stock_master ORDER BY stock_id ASC");
$item = '';
 while($row = mysql_fetch_assoc($getitem))
{
  $item .= '<option value = "'.$row['stock_id'].'">'.$row['stock_id'].'</option>';
}

$getdescription=mysql_query("SELECT * FROM 0_stock_master ");
$description = '';
 while($row2 = mysql_fetch_assoc($getdescription))
{
  $description .= '<option value = "'.$row2['description'].'">'.$row2['description'].'</option>';
}
?>
<!DOCTYPE html>
<!-- saved from url=(0047)http://css-tricks.com/examples/EditableInvoice/ -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">

    <title>Editable Invoice</title>

    <script src="./Editable Invoice_files/jquery-1.3.2.min.js"></script>
    <script src="./Editable Invoice_files/example.js"></script>
</head>

<body>
<div id="page-wrap">

        <textarea id="header">INVOICE</textarea>

        <div id="identity">


</body>
</html>


        <table id="items">

          <tbody><tr>
              <th>Item</th>
              <th>Description</th>
              <th>Unit Cost</th>
              <th>Quantity</th>
              <th>Price</th>
          </tr>

          <tr class="item-row">
              <td class="item-name"><div class="delete-wpr"><select name="age"> <?php echo $item; ?> </select><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>
              <td class="description"><select name="age"> <?php echo $description; ?> </select></td>
              <td><textarea class="cost">$0.00</textarea></td>
              <td><textarea class="qty">1</textarea></td>
              <td><span class="price">$0.00</span></td>
          </tr>



          <tr id="hiderow">
            <td colspan="5"><a id="addrow" href="javascript:;" title="Add a row">Add a row</a></td>
          </tr>

          <tr>
              <td colspan="2" class="blank"> </td>
              <td colspan="2" class="total-line">Subtotal</td>
              <td class="total-value"><div id="subtotal">$0.00</div></td>
          </tr>
          <tr>

              <td colspan="2" class="blank"> </td>
              <td colspan="2" class="total-line">Total</td>
              <td class="total-value"><div id="total">$0.00</div></td>
          </tr>
          <tr>
              <td colspan="2" class="blank"> </td>
              <td colspan="2" class="total-line">Amount Paid</td>

              <td class="total-value"><textarea id="paid">$0.00</textarea></td>
          </tr>
          <tr>
              <td colspan="2" class="blank"> </td>
              <td colspan="2" class="total-line balance">Balance Due</td>
              <td class="total-value balance"><div class="due">$0.00</div></td>
          </tr>

        </tbody></table>
  • 写回答

1条回答 默认 最新

  • duanjunao9348 2014-01-17 07:43
    关注

    you need to use ajax to post url id and get the result from ajax

    var data = 'id='+yourid; 
    $.post(
          'abc.php',
           data 
          success(function(resp){
              jsonData = $.parseJSON(resp);
              alert(jsonData);
          });
    

    abc.php

    id = $_POST['id'];
    your query
    echo json_encode(array(
    description => $description
    ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?