2011-01-17 8 views
0

안녕하세요, 저는 드롭 다운 메뉴에서 선택할 값에 따라 mysql 테이블의 모든 값을 가진 테이블을 보여주고 싶습니다. 예를 들어 드롭 다운 목록 메뉴에는 open이라는 값이 있습니다. 그 상태를 가진 테이블의 행을보고 싶을뿐입니다. 나는 이것을 위해 Ajax를 사용해야 할 것인가?종속 드롭 다운 내림차순 PHP

내 코드는 무엇입니까?

$status = $_POST['TipoStatus']; 
echo '<a href = "rnservices.php"> Create Service</a> '; 
echo '</br>'; 
echo '</tr><tr><td><label for="TipoStatus"> Status:</label></td><td>'; 
$query = "SELECT TipoStatus FROM status"; // First Remar 
     $result = queryMysql($query); 

      if (!queryMysql($query)) { 
    echo "Query fail: $query<br />" . 
      mysql_error() . "<br /><br />"; 
          } 
    else 
{ 
echo '<select name = "TipoStatus" size = "1">'; // or name="toinsert[]" 
// echo '<option value="none" selected="selected">None</option>'; 
while ($row_1 = mysql_fetch_array($result)) { 
    echo '<option value="' . htmlspecialchars($row_1['TipoStatus']) . ' selected="$row_1[9]" >' // Third remark 

    . htmlspecialchars($row_1['TipoStatus']) 
    . '</option>'; 

} 
echo '</select>'; 
echo '</p>'; 
}  

echo '<table border="1" >';  
echo '<tr>';  
echo '</br>'; 
echo '<th> Service ID</th>'; 
echo '<th>Title</th>'; 
echo '<th>Description</th>'; 
echo '<th>Notes</th>'; 
echo '<th>Submit By</th>'; 
echo '<th>Assigned Employee</th>'; 
echo '<th>Assigned Group</th>'; 
echo '<th>Category</th>'; 
echo '<th>Status</th>'; 
echo '<th>Urgency</th>'; 
echo '<th>Customer</th>'; 
echo '<th>Day Created</th>'; 
echo '</tr>'; 

$query = ("SELECT ServiceID, Title, Description, Notes, SubmitBy, AssignedEmp, " . 
"AssignedGroup, NameCategory, TipoStatus, TiposUrgencia, CustomerName, DayCreation FROM Service where TipoStatus = '$status' "); 
$result = queryMysql($query); 
echo 'resultado' . mysql_num_rows($result); 


while ($row = mysql_fetch_assoc($result)) { 

    echo '<tr>'; 

    echo '<td><a href="rnservices1.php?ServiceID='.$row["ServiceID"].'"> '.$row['ServiceID'] .' </a></td>'; 
    echo '<td>' .$row['Title']. ' </td>'; 
    echo '<td>'.$row['Description'].'</td>'; 
    echo '<td>'.$row['Notes'].'</td>'; 
    echo '<td>'.$row['SubmitBy'].'</td>'; 
    echo '<td>'.$row['AssignedEmp'].'</td>'; 
    echo '<td>'.$row['AssignedGroup'].'</td>'; 
    echo '<td>'.$row['NameCategory'].'</td>'; 
    echo '<td>'.$row['TipoStatus'].'</td>'; 
    echo '<td>'.$row['TiposUrgencia'].'</td>'; 
    echo '<td>'.$row['CustomerName'].'</td>'; 
    echo '<td>'.$row['DayCreation'].'</td>'; 

    echo '</tr>'; 
} 

mysqli_free_result($result); 


echo $ticket_select;`enter code here` 

echo '</table>'; 
echo '<form method = "post" action "rnseetickets.php">'; 
?> 
+1

JavaScript를 사용하려면 AJAX가 필요합니다. 여기 꽤 좋은 AJAX 튜토리얼을 찾을 수 있습니다 : http://www.w3schools.com/ajax/default.asp – Zak

답변

0

귀하의 코드가 약간 구불 구불하고, 명령 줄에서 또는 웹 페이지로이 작업을 실행하는 경우 내가 확실히 말할 수는 없지만, 당신은 SQL 결과를 필터링하고자하는 것처럼 보인다 옵션 드롭 다운이 있습니까?

// Run SQL 
$sql = "SELECT TipoStatus FROM status"; 
if (!empty($_GET['status'])) { 
    $sql .= "WHERE `value`=\"".addslashes($_GET['status'])."\""; 
} 
$result = queryMysql($sql); 

// Filter form 
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method="get">"; 
echo "<select name=\"status\"><option>open</option><option>other option</option></select>"; 
echo "<input type=\"submit\" value=\"Filter\">"; 
echo "</form>"; 

// Table 
// As you already have it 
0

인사말 : (당신이 페이지 새로 고침없이 필터링 할 경우) 그가 (당신이 페이지 새로 고침을 신경 쓰지 않는 경우) 간단한 형태로 수행하거나 AJAX와 함께 할 수 있습니다. 드롭 다운 상자의 onchange 이벤트에 대한 포럼을 제출할 수 있습니다.

확인이 링크 : 당신은 사용자가 드롭 뭔가를 선택 이제 때

을 '자바 스크립트 제출 onchange를'검색을 통해 더 많은 예제를 찾을 수 있습니다 javascript onchange submit

아래 양식을 제출 상자 당신은 당신을 사용할 수 있습니다 PHP 코드는 결과를 필터링합니다.