gpt4 book ai didi

php - 正确代码中的命令不同步

转载 作者:行者123 更新时间:2023-11-29 06:11:43 25 4
gpt4 key购买 nike

我通过 PHP 执行了以下查询,它以前像昨天一样工作,今天停止工作了,就是这样:

SELECT 
*,
(SELECT IF (pro.uid= '4342','True','False') FROM pro) AS 'uid'
FROM
Episodes, pro
ORDER BY
Episodes.id DESC
LIMIT 9

4342”已更改为 GET 参数,我遇到以下错误:

Commands out of sync; you can't run this command now

我的 PHP API 如下(片段):

<?php 
include_once "db_config.php";

DEFINE ('DB_HOST', $host);
DEFINE ('DB_USER', $user);
DEFINE ('DB_PASSWORD', $pass);
DEFINE ('DB_NAME', $database);

$mysqli = @($GLOBALS["___mysqli_ston"] = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD)) OR die ('Could not connect to MySQL');
@((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . constant('DB_NAME'))) OR die ('Could not select the database');

?>

<?php

if(isset($_GET['meaE'], $_GET['uid']))
{
$query="SELECT * , (SELECT IF (pro.uid= '".$_GET['uid']."','True','False') FROM pro ) AS 'uid' FROM Episodes,pro ORDER BY Episodes.id DESC LIMIT 9
";
$resouter = mysqli_query($GLOBALS["___mysqli_ston"], $query);

}

$set = array();

$total_records = mysqli_num_rows($resouter);
if($total_records >= 1){

while ($link = mysqli_fetch_array($resouter, MYSQLI_ASSOC)){

$set['APITest'][] = $link;
}
}
echo $val= str_replace('\\/', '/', json_encode($set));
?>

我想要以下输出:

    TABLE A       -  TABLE B 
ID NAME TEXT UID - Check_ID

我想要的查询:

Select * From Table A, Check if "134123123"is exists in B, if yes/no add a record for all the takeed records from Table A with the value of checking (True/False)

@sagi 查询发生了什么:

B表有3条记录,A表有10条记录,执行查询时,结果为30条记录,B表每条记录有A表的10条记录,uid记录值为uid 为 '134123123' 时为真,不为 '134123123' 时为假。

最佳答案

你的查询似乎是错误的,我不知道它昨天是如何工作的,但现在你在没有条件的情况下进行交叉连接(可能是正确的,但我对此表示怀疑) - 这意味着 episodes 将连接到 pro 中的每条记录。此外,您使用 IF 的子查询将返回超过 1 条记录,除非该表仅包含 1 条记录(这又是我怀疑的)。

试试这个:

SELECT distinct t.*, IF (s.uid is null,'True','False')  AS 'uid'
FROM Episodes t
Left JOIN pro s
ON(s.uid = '4342')
ORDER BY t.id DESC
LIMIT ?????

尝试使用子查询而不是连接:

Select t.*,
Case when exists(select 1 from pro s where s.uid = '4342')
Then 'true' else 'false'
End as 'uid'
From episodes t
Order by t.id desc
Limit 9;

关于php - 正确代码中的命令不同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37908734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com