我在DB中有2个表
u_m表: ID username_u nome_u identificaorM
信息表: ID 用户名 诺姆 sexo idade 糖尿病
我想在u_m表中使用identifyicarM在info表中搜索:
username = username_u 诺姆= nome_u
并显示在表格上
$id_M = @$_SESSION['id_M'];
$result = mysql_query("SELECT * FROM u_m WHERE identificadorM= SHA1('$id_M') ");
while($row2 = mysql_fetch_array($result)) {
$query2 = "SELECT * FROM info WHERE username=" . $row2['username_u'] . " and nome=" . $row2['nome_u'] . "";
}
echo "<table border='1' align='center'>
<tr>
<th><font color='white'>Registo</font></th>
<th><font color='white'>Nome do Paciente</font></th>
<th><font color='white'>Sexo</font></th>
<th><font color='white'>Data de Nascimento</font></th>
<th><font color='white'>Diabetes</font></th>
</tr>";
$i=0;
while($row = mysql_fetch_array($query2)) {
echo "<tr>";
echo "<td><font color='white'>" . ++$i . "</font></td>";
echo "<td><a href='validar2.php?username=$login&nome=" . $row['nome'] . "'><font color='white'>" . $row['nome'] . "</font></a></td>";
echo "<td><font color='white'>" . $row['sexo'] . "</font></td>";
echo "<td><font color='white'>" . $row['idade'] . "</font></td>";
echo "<td><font color='white'>" . $row['diabetes'] . "</font></td>";
echo "</tr>";
}
得到此警告:mysql_fetch_array():提供的参数不是第30行/home/a4490951/public_html/principalM.php中的有效MySQL结果资源
while($row = mysql_fetch_array($query2)) {
中的
答案 0 :(得分:1)
不确定任何与PHP相关的问题,但为什么不将您的查询与下面的单个查询相结合。在表JOIN
和info
上使用u_m
。
SELECT i.* FROM info i
JOIN u_m u on i.username = u.username_u
AND i.nome = u.nome_u
WHERE u.identificadorM = SHA1('$id_M')
答案 1 :(得分:0)
问题是$query2
是一个SQL字符串,并且您希望使用$result2 = mysql_query($query2)
将其更改为SQL结果。您还需要将逻辑移动到第一个while循环中,以便在正确的范围内执行$query2
。
顺便说一句,我强烈建议您学习如何使用SQL joins。我相信你可以通过一个SQL查询完成所有这些操作,为了提高效率,你真的应该这样做。