0

关于是否以及如何将 Mysqli 和查询与 PHP switch 语句结合使用以根据当前选择的 HTML 选择框的哪个选项来填充文本框的任何想法?到目前为止,我只能在初始页面加载时填充一个文本框,这只是通过 PHP switch 语句的默认情况。到目前为止,我的工作如下:

$mysql = new mysqli($db_host, $db_username, $db_password, $db_name)

switch("Not sure what to put here")
{
    case "corresponds with first <option> of select box but not sure how to do this" :
       $result = $mysql->query(---placeholder for SQL query---);

       while ($row = $result->fetch_object())
       {
          $queryResult = $row->---placeholder for column name---;
       }
       $textboxValue = $queryResult;
       break;
}
4

1 回答 1

0

看起来您将希望使用 javascript/jquery 和对 php 类的 ajax 调用,该类将进行数据库调用并将您需要存储的数据返回到文本框。

这是一个ajax调用的例子。您可以复制 javascript 代码并对其进行编辑以调用您自己的 php 类。

http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first(是的,它是 w3schools .. 但这段代码完成了工作)

替换xmlhttp.open("GET","ajax_info.txt",true);您要使用的php页面的链接,即xmlhttp.open("GET","loadTextBox.php?id=3",true);

更多信息:http ://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp

于 2012-09-06T19:29:53.253 回答