du8980919 2011-01-17 15:12
浏览 20

依赖下拉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">';
 ?>
  • 写回答

2条回答 默认 最新

  • du0204 2011-01-17 15:32
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)