开发者

Dependent dropdown PHP

Hello I want to show a table that have all the values from a mysql table but depending on the values that I will select from a dropdown menu. For example the dropdown list menu have a value named open. I just want to see the rows from the table that have that status. I will need to use Ajax for this?

Here is my code?

$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">';
 ?>


Your code is a little meandering, and I can't quite tell if you're running this from the command line or as a web page, but it seems like you're wanting to filter a SQL result with a drop-down of options? That can be done with a simple form (if you don't mind a page refresh) or with AJAX (if you want it to filter without a page refresh):

// 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


Greetings. You can submit a forum on the onchange event of the dropdown box.

Check this link: javascript onchange submit

You can find more examples by searching 'javascript onchange submit'

Now when the user selects something in the drop down box the form will submit and you can use your php code do filter the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜