dongsang6899 2014-12-20 10:45
浏览 77

检查每个MySQL查询结果行并执行操作

I have 2 frames, and a MySQL table full of elements.

The first frame has a dropdown menu and a submit button. The values (total 15) of dropdown list are taken from a MySQL database with the query SELECT DISTINCT (table_column) table_name.

<!DOCTYPE html>
<html>
<body>
<form method="post">
<?php
    include_once "CONNECT_TO_DB_SCRIPT.php";
    $query_ak = 'SELECT DISTINCT (column_name) FROM table_name';
    $result = mysql_query($query_ak) or die(mysql_error());
?>
<select name="exa">
<?php
    while ($row = mysql_fetch_assoc($result)) {
        echo '<option value="'.$row['ak_ex'].'">'.$row['ak_ex'].'</option>';
    }
?>
</select>
<input type="submit" value="GO!" name="go"/>
</form>
</body>
</html>

So now I want in the second frame to check if we select a value of the dropdown list to show the equivalent part of MySQL table where the values of a certain column_name are the same with the value I submited in dropdown menu.

Example: SELECT * FROM table_name where column_name= value_of_dropdown_menu.

I've tried this but it didn't work:

<?php
include_once "CONNECT_TO_DB_script.php";
$query_ak='SELECT DISTINCT (column_name) FROM table_name';
$result_ak = mysql_query ($query_ak) or die (mysql_error());

if (isset($_POST['go'])) { //checks if submit button has a value or it is NULL

    while ($row = mysqli_fetch_assoc($result_ak)) {
    if ($_POST["exa"] == "$row['ak_ex']") {
        $query = "SELECT * FROM table_name where column_name='.$row['ak_ex'].'";
        $result = mysql_query($query) or die('Query failed: ' . mysql_error());

…

close connection
?>
  • 写回答

2条回答 默认 最新

  • dtrgqjcd877528 2014-12-20 11:05
    关注

    Please note that your SQL result is from a mysql_query() function but you are using mysqli_fetch_assoc() to get data from it. Use mysql_fetch_array() Also you are going through a very hard process to get you posted data.and some syntax erorrs. in second frame go like this:

    <?php
    
        include_once "CONNECT_TO_DB_script.php";
        if (isset($_POST['go']))    {   //checks if submit button has a value or it is NULL
                $query= 'SELECT * FROM table_name where column_name=\''.$_POST["exa"].'\'';
                $result= mysql_query($query) or die ('Query failed: ' . mysql_error());
    .
    .
    .
    close connection
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂