我正在尝试从2个表中检索数据。首先,我从表dealerID
中检索了medicinalInfo
,然后使用此dealerID
我尝试从表users
收集此ID的信息,但是,
致命错误:未捕获错误:在C:\ xampp \ htdocs \ Trying \ search.php中调用boolean上的成员函数fetch_assoc():16堆栈跟踪:#0 {main}在C:\ xampp \ htdocs中抛出\在第16行尝试\ search.php
显示此错误..
码
<?php
$con = mysqli_connect("localhost", "root", "") or die(mysqli_error($con));
mysqli_select_db($con,"Ajmal") or die(mysqli_error($con));
$search = $_POST['search'];
$sql = "SELECT medicinName,pricerPerSheet,dealerID FROM medicinalinfo WHERE medicinName LIKE '%$search%'";
$result=$con->query($sql);
$count=$result->num_rows;
$val=$result->fetch_array();
$id=$val['dealerID'];
//echo $count;
$sql1 = "SELECT name,email,contact,ststus,distric,place FROM users WHERE id='$id'";
$query=$con->query($sql1);
$details=$query->fetch_assoc();
?>
第16行是$details=$query->fetch_assoc();
答案 0 :(得分:0)
也许你可以使用这个例子:
<?php
$con = mysqli_connect("localhost", "user", "pass", "database");
/* validate conection */
if (mysqli_connect_errno()) {
printf("failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($result = mysqli_query($con, $query)) {
/* get data */
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
/* free resul */
mysqli_free_result($resultado);
}
/* close conection */
mysqli_close($link);
?>