現在我已經創建了一個SQL數據庫,其中包含一些信息。使用PHP從SQL數據庫獲取信息
我現在有包含以下列三個表:
(1)表名=參議員;列= Dnumber,名稱 (2)表名=委員會;列= ID,委員會 (3)表名= memberCommittee;列= ID,Dnumber
我的選擇語句:
SELECT DISTINCT s.name參議員FROM參議員爲s,委員會如 C,memberCommittee爲m WHERE s.Dnumber = m.Dnumber和c.ID = m.ID 和c.ID =「1001」;
這樣做的目標是使用三個表獲取信息並顯示ID爲「1001」中的「名稱」。我的select語句的工作原理是向委員會中的人員顯示ID爲1001的人員,但我不太瞭解獲取信息的PHP部分。
這一部分:
*
$result = mysqli_query($conn, "SELECT DISTINCT s.name as Senator
FROM senators as s, committees as c, memberCommittee as m
WHERE s.Dnumber =m.Dnumber and c.ID = m.ID and c.ID = "1001");
while ($row = mysqli_fetch_assoc($result)){
unset($id, $Senator);
//$id = $row['Features'];
$Senator = $row['Senator'];
echo '<option value="'.$Senator.'">'.$Senator.'</option>';
}
*
有人能幫助我嗎?
<!DOCTYPE html>
<html>
\t <head>
\t \t <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\t \t \t <script language="javascript" type="text/javascript">
\t \t \t function dynamicdropdown(listindex) {
\t \t \t document.getElementById('senator').className = listindex;
\t \t \t </script>
\t \t \t
\t \t \t <style>
\t \t \t optgroup {
\t \t \t display: none;
\t \t \t }
\t \t \t select.Agriculture
\t \t \t optgroup.Agriculture
\t \t \t {
\t \t \t display: block;
\t \t \t }
\t \t \t
\t \t \t div#header{
\t \t \t padding: 1px;
\t \t \t color: yellow;
\t \t \t padding-left: 9px;
\t \t \t background-color: #000080;
\t \t \t }
\t \t \t
\t \t \t .category_div{
\t \t \t padding: 3px;
\t \t \t }
\t \t \t
\t \t \t .sub_category_div{
\t \t \t padding: 3px;
\t \t \t }
\t \t \t
\t \t \t .microphone{
\t \t \t padding: 3px;
\t \t \t }
\t \t \t
\t \t \t .body{
\t \t \t padding-right: 5px;
\t \t \t }
\t \t \t </style>
\t </head>
\t
<body>
\t <div class="header" id="header">
\t <h1>Indiana State Senate IT</h1>
\t </div>
\t <div class="room130">
\t <h3>Room 130</h3>
\t <form target="Room 130" action = "room130.php" method="POST">
\t \t <div class="category_div" id="category_div">Committee:
\t \t \t <select id="committee" name="committee" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
\t \t \t \t <option value="">Select Committee</option>
\t \t \t \t <option value="Agriculture">AGRICULTURE</option>
\t \t \t </select>
\t \t </div>
\t \t
\t \t <div class="sub_category_div" id="sub_category_div">
\t \t Individual:
\t \t \t <select name="senator" id="senator">
\t \t \t \t <option value="">Select individual</option>
\t \t \t \t \t <optgroup class="Agriculture">
\t \t \t \t \t \t <?php
\t \t \t \t \t \t \t $conn = mysqli_connect("db.soic.indiana.edu", "i308f16_team43", "my+sql=i308f16_team43", "i308f16_team43");
\t \t \t \t \t \t \t if(!$conn){
\t \t \t \t \t \t \t \t \t die("Connection Failed".myslqi_connect_error());
\t \t \t \t \t \t \t }
\t \t \t \t \t \t \t \t \t $result = mysqli_query($conn, "SELECT DISTINCT s.name as Senator FROM senators as s, committees as c, memberCommittee as m WHERE s.Dnumber = m.Dnumber and c.ID = m.ID and c.ID = "1001");
\t \t \t \t \t \t \t \t \t while ($row = mysqli_fetch_assoc($result)){
\t \t \t \t \t \t \t \t \t \t \t unset($id, $Senator);
\t \t \t \t \t \t \t \t \t \t \t //$id = $row['Features'];
\t \t \t \t \t \t \t \t \t \t \t $Senator = $row['Senator'];
\t \t \t \t \t \t \t \t \t \t \t echo '<option value="'.$Senator.'">'.$Senator.'</option>';
\t \t \t \t \t \t \t \t \t }
\t \t \t \t \t \t \t ?> \t \t \t \t \t \t \t \t
\t \t \t \t \t </optgroup>
\t \t \t \t </option>
\t \t \t </select>
\t \t </div>
</body>
</html>
檢查該行'$結果= mysqli_query($康恩,「SELECT DISTINCT s.name參議員FROM參議員爲s,委員會爲c,memberCommittee爲m WHERE s.Dnumber = m.Dnumber和c.ID = m.ID和c.ID =「1001」);'缺乏 - >「使用這個'$ result = mysqli_query($ conn,」SELECT DISTINCT s.name作爲Senator FROM參議員作爲s委員會c,memberCommittee as m WHERE s.Dnumber = m.Dnumber and c.ID = m.ID and c。ID ='1001'「)'您的單引號 –
@GuillermoAndresFuentesMoral更改了它......不確定變量在」While「語句中的含義 –
您的print_r變量'$ row'?顯示結果? –