doulong1987 2015-08-22 14:03
浏览 51
已采纳

而在while循环似乎不起作用 - PHP

Alright so I've been trying to replace a number from the database for the actual name, unfortunately it only returns nothing at all.

I'm not sure what I'm doing wrong here, Tried it multiple ways, as explained on other related questions, yet it doesn't seem to work. The first while seems to work, but the second doesn't do its job..(although in this setup it gives nothing at all)

here is my code:

<?php
include_once 'db_connect.php';

$query  = "SELECT bestel_nummer, bestel_datum, bestel_tijd, kkt_id, mwr_id
        FROM bestellingen";

$response = mysqli_query($mysqli, $query);


if ($response){

    echo '<table align="left" cellspacing="5" cellpadding="8">
            <td align="left"><b>bestel nummer<b></td>
            <td align="left"><b>bestel datum<b></td>
            <td align="left"><b>bestel tijd<b></td>
            <td align="left"><b>klanten nummer<b></td>
            <td align="left"><b>Medewerker<b></td></tr>';


while($row = mysqli_fetch_array($response)){
    $mwr_id = $row['mwr_id'];
    $query2 = "SELECT 'voornaam' FROM 'medewerkers' WHERE 'mwr_id' = $mwr_id LIMIT 1";
    $response2 = mysqli_query($query2, $mysqli);
            while($row2 = mysqli_fetch_array($response2)){
            

            echo '<tr><td align="left">'. 
        $row['bestel_nummer'].'</td><td align="left">'.
        $row['bestel_datum'].'</td><td align="left">'.
        $row['bestel_tijd'].'</td><td align="left">'.
        $row['kkt_id'].'</td><td align="left">'.
        $row2['voornaam'].'</td><td align="left">';
        echo'</tr>';
            }
    }


echo'</table>';
}
else{
    echo 'couldnt issue database query';
    echo mysqli_error($mysqli);
}



mysqli_close($mysqli);
?>

Thanks in advance.

</div>
  • 写回答

1条回答 默认 最新

  • duanhongyi2964 2015-08-22 14:07
    关注

    Maybe it's not the while loop, but the mysqli_query Seems like the arguments in the second query have a wrong order

    first query

    $response = mysqli_query($mysqli, $query);
    

    second query

    $response2 = mysqli_query($query2, $mysqli);
    

    This means no result, no while loop, check the response2 variable, the while loop should work, but actually the code itself looks unperformant.

    If you wanna have the most performance you should do it with one query, with something like Group and Join. I don't know your structure but it should be possible.

    If you try to query the db, in a loop it's a alway a very bad idea, image 100, 1000 users will trigger this code.. ohoohooo your server will probably go down men.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证