COUNT()以不同的方式运行

时间:2014-10-20 20:08:20

标签: php mysql count

我编写了代码,它在我的本地wamp服务器上运行。 计数(A.id)或$ count为1 ,一切正常。我上传了该文件并进入真实网站, $ count为3,尽管数据库相同(相同的记录)。


我改变了:

COUNT(A.id)>>>> (SELECT COUNT(id)FROM table1 WHERE lower(login_name)= lower(?))
$ stmt-> bind_param(' S',$ GET_USER); >>>> $ stmt-> bind_param(' ss',$ get_user,$ get_user);

这解决了这个问题。 $ count变成1.有人可以解释为什么会这样。
当然,查询应该从数据库中选择一条记录,具体取决于$ _GET中提供的用户名[' name']

$db = new mysqli($DBhost, $DBuser, $DBpassword, $DBdatabase);
$query = "SELECT COUNT(A.id), A.profile_public, A.id, A.login_name, A.user_title, A.user_title_color, A.banner, A.banner_position, A.registration_date, A.priv, A.ban, A.block, A.special_user, B.birth, B.birth_change, B.birth_pub, B.age, B.age_change, B.age_pub, B.country, B.country_change, B.country_pub, A.email, B.email_pub, A.movie_suggestions, A.accepted_suggestions, B.reputation, COUNT(C.movie), A.fav_pub, B.gender, B.gender_pub, B.gender_change, B.social, B.social_pub, B.social_change, B.about FROM table1 AS A LEFT JOIN table2 AS B ON A.id=B.userid LEFT OUTER JOIN table3 AS C ON A.login_name=C.user WHERE lower(A.login_name)=lower(?)";
$stmt = $db->prepare($query);
$stmt->bind_param('s',$get_user);
$stmt->execute();
$stmt->bind_result($count, $public, $id, $lg_name, $user_title, $user_title_color, $banner, $banner_position, $registration_date, $privs, $usr_ban, $block, $special_user, $birth, $birth_change, $birth_pub, $age, $age_change, $age_pub, $country, $country_change, $country_pub, $email, $email_pub, $movie_suggestions, $accepted_suggestions, $reputation, $count_favorites, $fav_pub, $gender, $gender_pub, $gender_change, $social1, $social_pub, $social_change, $about);
$stmt->fetch();

0 个答案:

没有答案