使用PHP中的下拉列表调用mysql过程

时间:2015-04-24 20:37:59

标签: php mysql

我的下拉表格如下:

 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
    <p>Get a Report of each Gene:<br>
        <select  name="Prot_Id">
            <!--option value="" selected disabled>Select a rating</option--> 
            <option value="" selected disabled></option>
            <option value="chr">chr12:111,843,752-111,889,427</option>
            <option value="chr">chr19:17,186,591-17,324,104</option>
            <option value="chr">chr2:102,927,962-103,015,21</option>
            <option value="chr">chr2:204,732,511-204,738,683</option>
            <option value="chr">chr4:123,372,626-123,377,650</option>
            <option value="chr">chr4:123,533,783-123,542,212</option>
            <option value="chr">chr6:159,456,027-159,466,184</option>
        </select>
    </p>

    <input type="submit" name="submit1" value="Go" />
</form>  

我有一个带有一个输入参数的MySQL存储过程Chrome_Seq(例如:chr2:102,927,962-103,015,21它是下拉框的显示名称)。现在我正在写一个PHP页面调用此过程并将结果显示为表。这是我的PHP代码:

<?php 

if (isset($_POST['chr'])) {

    echo "hi 11";
    $id=$_POST['chr'];

    echo "<table>";
    //connect to database
    $connection = mysqli_connect("localhost", "root", "", "KCC_Celiac_Disease");

    //run the store proc
    echo "hello";

    $query= "call Chromo_Seq(".'"'.$id.'")';

    $result = mysqli_query($connection, $query) or die("Query fail: " . mysqli_error());


    //loop the result set

    echo "<tbody>";
    // point to the beginning of the array
    $check = mysqli_data_seek($result, 0); 
    $rownew = mysqli_fetch_assoc($result);

    foreach($rownew as $k => $v ) {
        echo "<th>".$k."</th>";
    }

    $check = mysqli_data_seek($result, 0); 

    while ($rownew = mysqli_fetch_assoc($result)) {

        echo "<tr>";
        foreach($rownew as $k => $v) {
            echo "<td>".$v."</td>";
        }
        echo "</tr>"."<br>";
    } 
    echo "</tbody></table>";
}
?>   

每当我从下拉列表中选择一个值时,它应该使用该参数运行该过程并返回值,但我的输出中没有得到任何结果。它是空白的。

0 个答案:

没有答案