Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql查询依赖于其他表_Php_Mysql_Sql - Fatal编程技术网

Php mysql查询依赖于其他表

Php mysql查询依赖于其他表,php,mysql,sql,Php,Mysql,Sql,根据第二个表,我想从第一个表中选择两个 第一桌 ex_instagram_p: id (int) username (varchar) cpc (int) type (varchar) active (int) 第二桌 exchanges id (int) user (varchar) exid (int) 我想要的是: 选择ex_instagram_p中的值,确保它不等于exchanges.user=$username行在exchanges.id上不包含ex_instagram_

根据第二个表,我想从第一个表中选择两个

第一桌

ex_instagram_p:

id (int)
username (varchar)
cpc (int)
type (varchar)
active (int)
第二桌

exchanges

 id (int)
 user (varchar)
 exid (int)
我想要的是:

选择ex_instagram_p中的值,确保它不等于exchanges.user=$username行在exchanges.id上不包含ex_instagram_p.id的第二个表exchanges中的任何条目

让我澄清一下

例如,表1用于博客文章

因此,用户将显示文章!=他的用户名和active=1,type='。follow'

第二个表是视图

因此,如果第二个表中有一个user=$username,exid=firsttable.id的条目

此条目已被此用户查看,我不希望他再次查看

Actually i need if no entry on the exchanges table got the values of
user - exid
$username - i.id

if this doesn't exist is should continue
这是我创建的代码,但它不起作用

$prowz= mysql_query("SELECT i.*
FROM ex_instagram_p as i, exchanges as e
 HAVING COUNT(e.user = '".$username." And e.exid = i.id) = 0 
 WHERE 
 AND i.type = '".follow."' 
 AND i.active=1
 AND i.username != '".$username."'
ORDER BY i.cpc DESC
 LIMIT 1;");

有很多WHERE子句,但很简单

SELECT i.*
FROM ex_instagram_p as i, exchanges as e
WHERE i.id != e.exid
AND e.user = '".$username."'
AND i.type = '".follow."' 
AND i.active=1
AND i.username != '".$username."'
ORDER BY i.cpc DESC
LIMIT 1;
$follow应该是一个变量,或者只是字符串“follow”。这是一个未定义的常数

"SELECT i.* FROM ex_instagram_p i, exchanges e
 WHERE i.id != e.exid
 && e.user = '$username'
 && i.type = '$follow'
 && i.active = 1 
 && i.username != '$username'
 ORDER BY i.cpc DESC LIMIT 1;"

其中只能出现一次。在那之后是and@Strawberry这就是。@VMai抱歉,我不懂。@草莓:我链接到mysql的问题的唯一答案应该是mysqli。只是一个评论。让我们不要宣传20世纪C。加入公约好的。所以每个人都想用什么就用什么。在这种情况下,这两种方法都有效。实际上,如果Exchange表中没有条目获得user-exid$username-i.id的值,那么我需要这个值。如果这个值不存在,我需要继续使用COUNTe.user='。$username。e.exid=i.id=0,为什么?我从来没有见过伯爵这样用过。你确定不需要子查询吗?实际上,如果Exchange表中没有条目获得user-exid$username-i.id的值,我需要它。如果不存在,它应该继续。我不明白你在问什么。用户-exid$username-i.id?这在英语中意味着什么?我不知道我真正需要使用什么,但我真正需要的是以下内容。例如,我得到了两个表,一个用于博客主题,另一个用于主题视图。我想向用户显示仅针对其他用户的主题,而他还没有查看这些主题。