我似乎无法弄清楚这里发生了什么......或者为什么这不起作用。代码适用于不同的数据库...所以我不确定发生了什么?
<?php
//connect to the database
$con = new mysqli("localhost", "rreedy", "quixtar1");
$con->select_db("attendance");
//display success or failure
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . $con->connect_errno;
}
echo "<label for='evtCode'>Event</label><br/>";
echo "<select id='evtCode' class='form-control' name='evtCode'>";
echo "<option value=1>Text</option>";
$query = "SELECT * from tbldata";
$result = $con->query($query);
while($row = mysqli_fetch_array($result))
echo $row['courseName'];
echo "</select>";
?>
答案 0 :(得分:1)
你有一个错字,它应该是:
$result = $con->query($query);
答案 1 :(得分:0)
您的mysqli
对象位于$conn
。您还将程序和面向对象混合在一起。
echo "<option value=1>Text</option>";
$query = "SELECT * from tbldata";
$result = $con->query($query);
while($row = $result->fetch_array(MYSQLI_ASSOC))
echo $row['courseName'];
echo "</select>";
$con->query()
$row = $result->fetch_array(MYSQLI_ASSOC)