注意:从数据库请求数据时,数组到字符串的转换是错误的

时间:2013-12-19 04:05:36

标签: php mysql arrays string

我环顾四周,找不到问题的答案。 我试图从数据库中获取一行,但它只是给我一个通知说:

注意:/ xampp /...

中的数组到字符串转换

这是我的代码:

$sql6 = mysql_query("SELECT * FROM replies WHERE thread_id = $thread_id");
    $numRows = mysql_num_rows($sql6);
    $replies = '';
    if ($numRows < 1) {
        $replies =  "There are no replies yet, you can make the first!";
    } else {
        while ($rows = mysql_fetch_array($sql6)) {
            $reply_content = $rows[5];
            $reply_username = $rows[7];
            $reply_date = $rows[8];
            $reply_author_id = [4];

            $sql9 = mysql_query("SELECT * FROM users WHERE id = $reply_author_id");
            $numRows = mysql_num_rows($sql); 
            if ($numRows < 1) {
                while ($rows = mysql_fetch_array($sql)) {
                    $reply_user_fn = $rows['first_name'];
                    $reply_user_ln = $rows['last_name'];
                    $reply_user_id = $rows['id'];
                    $reply_user_pp = $rows['profile_pic'];
                    $reply_user_lvl = $rows['user_level'];
                    $reply_user_threads = $rows['threads'];
                    $reply_user_email = $rows['email'];


                    }
                }
            }
        }

请帮帮我。我对PHP很新,我不知道我做错了什么。

2 个答案:

答案 0 :(得分:0)

我也是PHP的新手,但不应该在你的比较中的代码

mysqli_fetch_array($sql6)

而不是

mysql_fetch_array($sql6)?

答案 1 :(得分:0)

<强>错字

 $sql9 = mysql_query("SELECT * FROM users WHERE id = $reply_author_id");
 $numRows = mysql_num_rows($sql); //here $sql will be $sql9

----------------------------------------------- ^

 if ($numRows < 1) {
 while ($rows = mysql_fetch_array($sql)) {//here $sql will be $sql9

----------------------------------------------- -------- ^

正确的代码:

 $sql9 = mysql_query("SELECT * FROM users WHERE id = $reply_author_id");
 $numRows = mysql_num_rows($sql9); //here $sql will be $sql9
 if ($numRows < 1) {
 while ($rows = mysql_fetch_array($sql9)) {//here $sql will be $sql9