使用GET方法运行php脚本并查询数据库以获得结果

时间:2014-09-07 09:53:10

标签: php html sql-server

我向其他人提出了一个非常类似的问题而道歉,但我无法理解这一点。基本上,我需要显示一个html页面,我已经设置了一个从PHP脚本获取信息的表单。到目前为止,在HTML中,我有

<!-- FORM START -->
    <form action="checkscript.php" method="get">
        <!-- Input text box with styling over image -->
        <input type="text" style="position:relative; left:8px; top:-75px; font-family:arial; font-size:32px; background-color:transparent; height:44px; width:268px; border:none; font-weight:bold; text-transform:uppercase; text-align:center;" placeholder="TICKET ID" maxlength="7" name="ticketId" />
        <!-- Button with styling to execute PHP script -->
        <button type="button" style="position:relative; top:-45px; width:300px; height:30px; font-family:arial; font-size:16px; font-weight:bold;">Find Details</button> 
    </form>

在查询数据库的checkscript.php中,我有

<?php
$db = mssql_connect("dbsrv02", "requsr", "");
mssql_select_db("ticketDb",$db);
$result = mssql_query("SELECT ticketId, StageOne, StageTwo, StageThree",$db);
$num = mssql_num_rows($result);
$regPlate = $_GET['ticketId'];
$i = 1;
if ($myrow = mssql_fetch_array($result)) do {
    <<< what goes here? >>>
}
if ($num > $i) printf(",");
$i++;
} while ($myrow = mssql_fetch_array($result));
else {
echo "Sorry, nothing there to see!";
}
?>

现在,我需要的是知道在什么地方放置&lt;&lt;&lt;什么在这里? &GT;&GT;取代。我需要使用像

这样的东西
if ($myrow["StageOne"] = "Completed" and $myrow["StageTwo"] = "Uncomplete" and $myrow["StageThree"] = "Uncomplete" {
    $stage = "StageOne"
}

(已完成或未完成的单词将位于&#34; StageOne&#34;,&#34; StageTwo&#34;&#34; StageThree&#34;)列下的行中。

在&#39; ticketId&#39;的同一行中查找结果,以及如何显示以HTML格式检索的信息,例如如果$ stage变量=&#34; StageOne&#34;,则HTML中会显示特定元素。

抱歉,我知道这一定很简单,但我可以在这里提供一些帮助。任何帮助将不胜感激,特别是如果你能使它非常详细!

由于

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

<?php
$db = mssql_connect("dbsrv02", "requsr", "");
mssql_select_db("ticketDb",$db);
$result = mssql_query("SELECT ticketId, StageOne, StageTwo, StageThree",$db);
$num = mssql_num_rows($result);
$regPlate = $_GET['ticketId'];
$i = 1;

// creating table header
echo "<table>";
echo "<tr> 
    <td> num </td> 
    <td> stage1 </td> 
    <td> stage2 </td> 
    <td> stage3 </td> 
    <td> stage </td> 
    </tr>";

while ($myrow = mssql_fetch_array($result))  {
    if ($myrow["StageOne"] = "Completed" and $myrow["StageTwo"] = "Uncomplete" and $myrow["StageThree"] = "Uncomplete" {
       $stage = "StageOne"
    }
    // fecthing row
    echo "<tr>";
    echo "<td> " . $num . "</td>";
    echo "<td> " . $myrow["StageOne"]  . "</td>";
    echo "<td> " . $myrow["StageTwo"]  . "</td>";
    echo "<td> " . $myrow["StageThree"]  . "</td>";
    echo "<td> " . $stage   . "</td>";
    echo "</tr>";
}
$i++;
} 
// table tag closing
echo "</table>";

if ($num < 1){ // if there nothing
echo "Sorry, nothing there to see!";
}else{
echo "There are " . $num "s data";
}
?>