我有一个网页,它向我的MySQL数据库发送一个查询,以检索有关我公司供应商的信息并回复结果(到目前为止都很好)。然后,它会进行第二次查询,以检查是否有与该供应商关联的已知联系人:
while ($row = mysqli_fetch_array($result)) {
$contact = $row["contact"];
echo $row["name"] . "<br>" . $row["category"] . "<br>" . "Telephone: " .
$row["telephone"] . "<br>" . "Fax: " . $row["fax"] . "<br>" .
$row["email"] . "<br>" . $row["address"] . "<br>" .
$row["postcode"] . "<br><br>" . "Contact: " .
$contact . "<br>";
$resultContact = mysqli_query($con,"SELECT * FROM contacts WHERE name =
'$contact'");
while($rowContact = mysqli_fetch_array($resultContact)) {
echo $rowContact["telephone"] . "<br>" . $rowContact["email"];
echo "<br>";
}
}
($row
来自第一个查询并且有效。)但是,echo $rowContact["telephone"] . "<br>" . $rowContact["email"];
只打印空格。
由于
编辑:如果我在Where子句中使用字符串文字,它就可以正常工作。但是,我使用的变量与我现在在第一个查询中完全相同,并且有效!我很困惑:(
编辑2:第一个查询:$result = mysqli_query($con,"SELECT * FROM suppliers WHERE LOWER(name) = LOWER('$searchText')");
编辑3:执行var_dump($resultContact);
的结果:object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(4) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) }
我猜这意味着查询将返回表格ok,但Where子句不是不要将我想要的联系人姓名与...进行比较......
答案 0 :(得分:0)
您的查询必须是mysql_query,而不是mysqli_query。 这是正确的代码:
//Your db connection
mysql_connect('localhost','root','');
mysql_select_db('database');
//queries and data
$result = mysql_query("SELECT * FROM suppliers WHERE LOWER(name) = LOWER('$searchText')");
while ($row = mysql_fetch_array($result)) {
$contact = $row["contact"];
echo $row["name"] . "<br>" . $row["category"] . "<br>" . "Telephone: " .
$row["telephone"] . "<br>" . "Fax: " . $row["fax"] . "<br>" .
$row["email"] . "<br>" . $row["address"] . "<br>" .
$row["postcode"] . "<br><br>" . "Contact: " .
$contact . "<br>";
$resultContact = mysql_query("SELECT * FROM contacts WHERE name =
'$contact'");
while($rowContact = mysql_fetch_array($resultContact)) {
echo $rowContact["telephone"] . "<br>" . $rowContact["email"];
echo "<br>";
}
}