我尝试访问用户搜索页面时发生数据库错误,错误号:1242

时间:2019-10-17 10:52:36

标签: php mysql codeigniter

当我尝试从网站访问搜索页面时,出现此错误,但是只有我使用Mens个人资料访问搜索时,当我使用另一种类型时会产生此错误。请问我该如何解决?

A PHP Error was encountered
Severity: Warning

Message: mysqli::query(): (21000/1242): Subquery returns more than 1 row

Filename: mysqli/mysqli_driver.php

Line Number: 307

Backtrace:

File: /home4/trans4date/public_html/application/models/Mdl_common.php
Line: 86
Function: query

File: /home4/trans4date/public_html/application/controllers/Profiles.php
Line: 696
Function: allSelects

File: /home4/trans4date/public_html/index.php
Line: 308
Function: require_once

A PHP Error was encountered
Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home4/trans4date/public_html/system/core/Exceptions.php:271)

Filename: core/Common.php

Line Number: 564

Backtrace:

File: /home4/trans4date/public_html/application/models/Mdl_common.php
Line: 86
Function: query

File: /home4/trans4date/public_html/application/controllers/Profiles.php
Line: 696
Function: allSelects

File: /home4/trans4date/public_html/index.php
Line: 308
Function: require_once     

发生数据库错误     错误编号:1242

Subquery returns more than 1 row

SELECT u.profileurlslug, u.fname, u.age, u.photo, u.transgendertype, u.transgendertype, u.user_type, u.orientations, u.relationship_status, u.country, u.country_code, u.city, u.totalphotos, u.active, u.User_ID, u.gender, (SELECT user_idfrom FROM dating_favourite WHERE user_idto=u.User_ID) as favourite FROM dating_users as u WHERE u.User_ID!='' AND u.gender='lb' AND u.active='confirm' AND u.User_ID!='9967' ORDER BY u.lastloggedin DESC limit 0, 20

Filename: models/Mdl_common.php

Line Number: 86

这里是代码(当他们尝试首先显示最后一个登录的用户时会发生这种情况)

else{
    $sqlquery="SELECT u.profileurlslug, u.fname, u.age, u.photo, u.transgendertype, u.transgendertype, u.user_type, u.orientations, u.relationship_status, u.country, u.country_code, u.city, u.totalphotos, u.active, u.User_ID, u.gender, (SELECT user_idfrom FROM ".$this->tableprefix."favourite WHERE user_idto=u.User_ID) as favourite FROM ".$this->tableprefix."users as u WHERE u.User_ID!=''".$cnd." ORDER BY u.lastloggedin DESC $limitstr";
    $records=$this->mdl_common->allSelects($sqlquery);
    $data['records']=$records;
    $data['remaining']=$total-($limitstart+$totalrec);
    $this->load->view('header',$data);

当我回到这段代码时,再次正常工作

$sqlquery="SELECT u.profileurlslug, u.fname, u.age, u.photo, u.transgendertype, u.transgendertype, u.user_type, u.orientations, u.relationship_status, u.country, u.country_code, u.city, u.totalphotos, u.active, u.User_ID, u.gender, (SELECT user_idfrom FROM ".$this->tableprefix."favourite WHERE user_idto=u.User_ID) as favourite FROM ".$this->tableprefix."users as u WHERE u.User_ID!=''".$cnd." $limitstr";

代码在这里

code for the page profiles.php

1 个答案:

答案 0 :(得分:0)

子查询获取喜欢的列名返回多于一行。如果子查询返回相同的值,则可以区分关键词。