2013-10-07 2 views
-1

나는 mysql 레코드를 보여주는 드롭 다운 선택을 가지고있다. 내가 원하는 것은 다른 드롭 다운을 만들어 콤보 박스를 선택하는 것입니다.php mysql에서 콤보 박스를 만드는 방법은 무엇입니까?

bid.php

<script type="text/javascript" src="javascript/jquery.js"></script> 
<script> 
function showUser(str) { 
    var $txtHint = $('#txtHint'); 
    if (str == "") { 
     $txtHint.html(''); 
     return; 
    } 
    $txtHint.load('bid_list.php?q=' + str) 
} 
</script> 
</head> 
<body onload=showUser(str="ALL")> 

<div id="main" style="width:1150px;margin:0 auto;padding:10px;"> 
<div id="title" style="width:1150px;margin:0 auto;text-align:center;font-size:30px;color:gray;text-shadow:2px 2px #000;font-family:Verdana, Tahoma, sans-serif;"><h3>BIDDING LIST</h3></div> 
<div id="container" style="width:1100px;"> 
<?php 
$mysqli = new mysqli("localhost", "root", "", "app"); 
$result = $mysqli->query("SELECT bid FROM procurement WHERE bid LIKE '13-___' OR bid LIKE '1_-___' OR bid LIKE '2_-___' GROUP BY bid ORDER BY bid"); 

$option = ''; 
while($row = $result->fetch_assoc()) 
{ 
    $option .= '<option value = "'.$row['bid'].'">'.$row['bid'].'</option>'; 
} 
?> 

<div style="text-align:center;"> 
<select name="users" onchange="showUser(this.value)" style="overflow:scroll;width:100px;"> 
     <option value="ALL" selected='ALL'>ALL</option> 
     <?php echo $option; ?> 
</select> 
</div> 
<br> 

<div id="txtHint"></div> 

bid_list.php 난에서 선택하는 경우 두 번째 드롭 다운은, 모든 PO_NUMBER을 보여줍니다 무엇 드롭 다운 값이 13-001 같은 경우는 내가하고 싶은

<html> 
    <head> 
     <title></title> 
     <link rel="stylesheet" href="css/style.css" type="text/css" id="" media="print, projection, screen" /> 
     <script type="text/javascript" src="javascript/jquery.tablesorter.js"></script> 
     <script type="text/javascript"> 
     $(function() { 
      $("table").tablesorter({debug: true}); 
     }); 
     </script> 
<script type="text/javascript"> 
    $(function(){ 
    var tfrow = document.getElementById('tfhover').rows.length; 
    var tbRow=[]; 
    for (var i=1;i<tfrow;i++) { 
     tbRow[i]=document.getElementById('tfhover').rows[i]; 
     tbRow[i].onmouseover = function(){ 
      this.style.backgroundColor = '#f3f8aa'; 
     }; 
     tbRow[i].onmouseout = function() { 
      this.style.backgroundColor = '#ffffff'; 
     }; 
    } 
    }); 
</script> 
</head> 
<body> 

<?php 
$mysqli = new mysqli("localhost", "root", "", "app"); 
$q = $_GET["q"]; 
$where = ''; 
if ($q != 'ALL') { 
    $where = " WHERE bid='$q' "; 
} 
$result1 = $mysqli->query(" 
    SELECT bid, item_name, item_description, unit, unit_cost, quantity, supplier, po_number, po_date, counter, SUM(unit_cost*quantity) AS total_amount 
    FROM procurement 
    $where 
    GROUP BY counter ORDER BY bid 
"); 
echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;"> 
     <thead> 
     <tr> 
      <th title="Item Name">Item Name</th> 
      <th title="Item Description">Description</th> 
      <th title="Example : Pc, Pcs, Box and Etc.">Unit</th> 
      <th title="Item Price">Unit Cost</th> 
      <th title="Total Item Quantity">QTY</th> 
      <th title="Total Price">Total Amount</th> 
      <th title="Name of Supplier">Supplier</th> 
      <th title="Purchase Order #">PO #</th> 
      <th title="Purchase Order Date">PO Date</th> 
     </tr> 
     </thead>'; 
     echo'<tbody>'; 
while($row = $result1->fetch_assoc()){ 
if($row['bid'] != '') 
{ 
echo'<tr> 
      <td>'.$row['item_name'].'</td> 
      <td>'.$row['item_description'].'</td> 
      <td>'.$row['unit'].'</td> 
      <td>'.number_format($row['unit_cost'], 2, '.', ',').'</td> 
      <td>'.$row['quantity'].'</td> 
      <td>'.number_format($row['total_amount'], 2, '.', ',').'</td> 
      <td>'.$row['supplier'].'</td> 
      <td>'.$row['po_number'].'</td> 
      <td>'.$row['po_date'].'</td> 
     </tr></tbody>'; 
     } 
     } 
    echo "</table>"; 

if (!$mysqli) { 
    die('Connect Error: ' . mysqli_connect_error()); 
} 
mysqli_close($mysqli); 
    ?> 

</body> 
</html> 

두 번째 드롭 다운은 po_number의 모든 레코드를 12-12-CO 397과 같이 테이블에 표시합니다. 그렇게하는 방법?

+0

HTML과 SQL을 별도로 배우는 것이 필연적입니다. mysqli는 어떤 콤보 상자와도 아무 관련이 없기 때문에 질문을 대답 할 수 없게됩니다. –

답변

0

나는이 모든 것을 직접 알아 냈으므로 도움이되기를 바랍니다. 뷰에서

: 나는 jQuery 플러그인을 만들어

<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="/js/dynamicSelect.js"></script> 
<script> 
$(document).ready(function() { 
    $("#selectToUpdate").dynamicSelect($("#changeTriggersUpdate"),"actionName.php"); 
}); 
</script> 

내가 내 서버 측 코드를 쓴 '$ .fn.x ='jQuery를

$.fn.dynamicSelect = function(trigger, action) { 
    var dynamicSelect = $(this); 
    trigger.on('change', function() { 
     if(trigger.val() > 0){ 
      $.getJSON(action, {searchVal: $(this).val()}, function(html) { 
       dynamicSelect.html(html); 
      }); 
     } else{ 
      dynamicSelect.html(''); 
     } 
    }); 
}; 

에 추가를 dynamicSelect.js Yii 프레임 워크이므로 잘 할 수는 없지만 수행해야 할 작업에 대한 아이디어를 제공해야합니다.

public function actionVehicleSearch() 
{ 
      $searchVal = $_REQUEST['searchVal']; 
      $vehicles = Vehicle::model()->findAll(" 
         customerID LIKE ? 
         ", array('%' . $searchVal . '%')); 
      $str = ''; 
      foreach ($vehicles as $vehicle) { 
       $str .= '<option value="'. $vehicle->vID .'">'. $vehicle->VIN .'</option>'; 
      } 

      echo CJSON::encode($str); 
} 
+1

HTML이 아닌 JSON을 보냅니다. –

+0

방법/이유를 자세히 설명해 주시겠습니까? 감사! – Nick

관련 문제