很少警告[期望参数] [英] Few warnings [expects parameter]

查看:74
本文介绍了很少警告[期望参数]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用此代码显示行数,但它一直显示

I've been trying to display the number of rows using this code but it keep says

1行错了

<?php

            $link = mysql_connect("localhost", "gamin1_forum", "password123");
            mysql_select_db("gamin1_forumdb", $link);

            $result = mysql_query("SELECT COUNT(*) FROM smf_personal_messages", $link);
            $num_rows = mysql_num_rows($result);

            echo "$num_rows Rows";

            ?>

行大约是1443,但它一直说1

Rows are approximately 1443 but it kept saying 1

推荐答案

是的,mysql_num_rows()告诉您返回了一个行".您需要检查返回的行的值以获取计数.试试这个

This is true, mysql_num_rows() is telling that there was one "row" returned. You need to check the value of the returned row to get your count. Try this

$link = mysql_connect("localhost", "gamin1_forum", "password123");
$result = mysql_query("SELECT COUNT(*) as cnt FROM smf_personal_messages", $link);
$row = mysql_fetch_array($result);

echo ($row['cnt']);

另一方面,出于安全原因,不应使用mysql_ *函数.尝试PDO/mysqli_ *函数

On a side note, you should not use mysql_* functions for security reasons. Try PDO/mysqli_* functions

这篇关于很少警告[期望参数]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆