在一个查询中加入/查看Mysql中的三个表(Join/Look In Mysql Three Tables In One Query)
我决定创建人们你可能知道的系统,但我已经解决了一个问题,似乎我需要加入三个表来带来相关的结果。
目的是在数据库表中检查可能根据我朋友的朋友知道的朋友
(if user1 = user2 and user2 = user4 posibile user1 knows user4, user4 is a suggestion)
我使用以下代码来检查这个并且是按计划工作。SELECT `friendpin` AS `possible_friend_id` FROM `pinme` WHERE `senderpin` IN ( SELECT `friendpin` FROM `pinme` WHERE `senderpin` = $userlogged ) AND `friendpin` NOT IN ( SELECT `friendpin` FROM `pinme` WHERE `senderpin` = $userlogged ) AND NOT `friendpin` = $userlogged GROUP BY `possible_friend_id` ORDER BY COUNT( * ) DESC LIMIT 0 , 3
因此,
REQUEST
表中的建议人员状态可能已经向您提出待处理请求,但仍然显示为建议的朋友,或者在BLOCKED
表中,建议的朋友被阻止但仍然显示给您作为建议的朋友。 因此我想消除这种行为。 建议的人不应该在REQUEST
表或BLOCKED
表中退出。谁能帮我解决这个问题?
以下是
REQUEST
表,PINME
表和BLOCKED
表结构REQUEST TABLE: senderpin - id of the person who send request friendpin - receivers request id BLOCKED TABLE: user1_id - a person who block user2_id user2_id - the blocked person by user1_id PINME TABLE: PINME table: the table which keep relations structure: 1,2 2,2 | 4,8 8,4 senderpin - id of the person who send request friendpin - receivers request id
感谢致敬
I decided to create People You May Know System but i have accounted a problem where it seems I need to join three tables to bring relevant results.
The aim is to check in database table for possible friends one may know based on friend of my friend
(if user1 = user2 and user2 = user4 posibile user1 knows user4, user4 is a suggestion)
I have used the following code to check this and is working as to plan.SELECT `friendpin` AS `possible_friend_id` FROM `pinme` WHERE `senderpin` IN ( SELECT `friendpin` FROM `pinme` WHERE `senderpin` = $userlogged ) AND `friendpin` NOT IN ( SELECT `friendpin` FROM `pinme` WHERE `senderpin` = $userlogged ) AND NOT `friendpin` = $userlogged GROUP BY `possible_friend_id` ORDER BY COUNT( * ) DESC LIMIT 0 , 3
Thus its possible that the suggested person status in
REQUEST
table he/she has already a request pending to you but still being shown as suggested friend or in theBLOCKED
table the suggested friend was blocked but still appear to you as suggested friend. therefore I would like to eliminate this behavior. a suggested person should not be exits either inREQUEST
table orBLOCKED
table.Can anyone help me solve this?
the following are the
REQUEST
table,PINME
table andBLOCKED
table structureREQUEST TABLE: senderpin - id of the person who send request friendpin - receivers request id BLOCKED TABLE: user1_id - a person who block user2_id user2_id - the blocked person by user1_id PINME TABLE: PINME table: the table which keep relations structure: 1,2 2,2 | 4,8 8,4 senderpin - id of the person who send request friendpin - receivers request id
Thanks and regards
原文:https://stackoverflow.com/questions/17399624
最满意答案
像这样定义它:
function mytheme_preprocess_page(&$variables, $hook = null) {
使hook参数可选,然后你可以调用这样的函数:
mytheme_preprocess_page($var);
或mytheme_preprocess_page($var, $another_var)
。在第一种情况下,
$hook
将为null
,在第二种$hook
中将具有$another_var
的值您可以像这样检查您的函数:
if ($hook === null) {
调用两者中的哪一个defining it like this:
function mytheme_preprocess_page(&$variables, $hook = null) {
Makes the hook parameter optional, you then can call the function like this:
mytheme_preprocess_page($var);
ormytheme_preprocess_page($var, $another_var)
.In the first case
$hook
will benull
, in the second$hook
will have the value of$another_var
You can check in your function like this:
if ($hook === null) {
Which of the two is called
相关问答
更多-
正如Paul Crovella指出的那样,整个脚本被编译,然后按照它编写的顺序执行。 对我来说更有趣的是嵌套函数的顺序,如: echo ucfirst(strtolower("bOB")); //Bob strtolower()先运行,然后运行ucfirst() 。 As Paul Crovella points out, The entire script is compiled, then executed in the order it is written. More interesting to ...
-
如何在functions.php上使用多个pre_get_posts?(How to use multiple pre_get_posts on functions.php?)[2023-11-10]
这在食典委中有所涉及。 你应该使用一个回调: function my_pre_get_posts( $query ){ if ( is_post_type_archive('cpt_1') ) { // Do stuff for a custom post type } elseif ( is_post_type_archive('cpt_2') ) { // Do stuff for a different custom post type } } ... -
你不需要评估任何东西: $function1 = 'print'; $function2 = 'implode'; $arr = array('arg1', 'arg2'); $function1($function2(', ', $arr)); 实际上,您甚至可以使用变量变量: $foo = 'print'; $bar = 'foo'; $$bar('hello'); You don't need to eval anything: $function1 = 'print'; $function2 ...
-
结合多个PHP函数(Combining multiple PHP functions)[2022-04-02]
像这样定义它: function mytheme_preprocess_page(&$variables, $hook = null) { 使hook参数可选,然后你可以调用这样的函数: mytheme_preprocess_page($var); 或mytheme_preprocess_page($var, $another_var) 。 在第一种情况下, $hook将为null ,在第二种$hook中将具有$another_var的值 您可以像这样检查您的函数: if ($hook === null) ... -
你可以使用call_user_func_array : function __call($method, $args) { call_user_func_array(array(&$this->c, $method), $args); } 请注意,这不会表现得那么好。 you can use call_user_func_array: function __call($method, $args) { call_user_func_array(array(&$this->c, $metho ...
-
mysql_query不返回行本身, 它返回一个需要传递给mysql_fetch_array()或mysql_fetch_assoc()等函数的资源来处理表结果; 你不能只是简单地使用mysql_query的返回值。 如果你只是将SQL查询合并为一个,那也可能会更好。 $result = mysql_query("SELECT round(AVG(cop),1) AS 'avg_cop', round(AVG(temp),1) AS 'avg_temp' FROM table WHERE timestamp ...
-
我建议你复制你的$headers并命名为$headers2并使用 mail($to, $subject, $body_sms, $headers2); 这可能是问题所在。 I suggest you make a copy of your $headers and name it $headers2 and use mail($to, $subject, $body_sms, $headers2); that may be the problem.
-
那么基于这个前提,你可以设计如下的东西: 在这样的示例请求中: xmlhttp.open("GET","server.php?action=save",true); 然后在PHP中: if(isset($_GET['action'])) { $action = $_GET['action']; switch($action) { case 'save': saveSomething(); break; case 'g ...
-
有几种选择。 选项1.在每个函数内声明数据库连接全局。 sqlFunctions.php: 选项2. ...
-
您可以注册一个tick功能来实现这一目标 declare(ticks = 1); $calls = array(); function tracer() { global $calls; $bt = debug_backtrace(); if (count($bt) <= 1) return; $function = $bt[1]; $call = $function['function']; if (isset($function['class'])) { ...