即使数据库中有值,SQL查询也会在浏览器中返回Array。我已经尝试了phpmyadmin中的查询,它可以工作但不在我的php文档中。
require_once('connect.php');
$query = "SELECT `id` FROM `questions` WHERE round='1' AND year='2016'";
$sql = mysqli_query($dbconnect, $query);
$row = mysqli_fetch_array($sql, MYSQLI_ASSOC);
几乎相同的查询在不同的php文档中有效。有什么建议有什么不对吗?还应该说查询应该返回整数。
答案 0 :(得分:2)
SELECT
IF((labrep.lab_status_id = 2
&& labrep.mhc_status = 'MHC'),
MIN(stepmap.order_seq_num) + 1,
MIN(stepmap.order_seq_num)) AS step_order_seq_num
FROM
`t_patient_mhc_step_group_mapping` stepgroup
INNER JOIN
t_patient_mhc_step_mapping stepmap ON stepgroup.step_id = stepmap.step_id
AND stepmap.mhc_step_status = 1
INNER JOIN
`t_patient_mhc_mapping` mhcmap
INNER JOIN
`t_lab_test_report` labrep ON labrep.op_ip_appt_id = mhcmap.appt_id
WHERE
mhcmap.appt_id = 81
您只选择$query = "SELECT `id` FROM `questions` WHERE round='1' AND year='2016'";
列。如果您希望回显更多列,则需要在查询中添加它们。
即:
id
然后循环结果:
$query = "SELECT `id`, `col2`, `col3` FROM `questions` WHERE round=1 AND year=2016";
同时检查查询错误并假设连接成功while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)) {
echo $row['id'];
// echo "<br>";
// echo $row['col2'] . "<br>";
// echo $row['col3'];
}
。
其他参考:
答案 1 :(得分:0)
如果您想显示其他列的数据,那么必须在*
'id'
require_once('connect.php');
$query = "SELECT * FROM `questions` WHERE round='1' AND year='2016'";
$sql = mysqli_query($dbconnect, $query);