0
我創建了一個php函數來從sql表中提取記錄subscriptions
,我想向mysql_query添加一個條件以忽略表中存在的表subscriptions
中的記錄removed_items
,這是我的代碼;MYSQL從表1中獲取表2中不存在的記錄
function subscriptions_func($user_id, $limit){
$subs = array();
$sub_query = mysql_query("
SELECT `subscriptions`.`fo_id`, `subscriptions`.`for_id`, `picture`.`since`, `picture`.`user_id`, `picture`.`pic_id`
FROM `subscriptions`
LEFT JOIN `picture`
ON `subscriptions`.`fo_id` = `picture`.`user_id`
WHERE `subscriptions`.`for_id` = $user_id
AND `picture`.`since` > `subscriptions`.`timmp`
GROUP BY `subscriptions`.`fo_id`
ORDER BY MAX(`picture`.`since_id`) DESC
$limit
");
while ($sub_row = mysql_fetch_assoc($sub_query)) {
$subs [] = array(
'fo_id' => $sub_row['fo_id'],
'for_id' => $sub_row['for_id'],
'user_id' => $sub_row['user_id'],
'pic_id' => $sub_row['pic_id'],
'since' => $sub_row['since']
);
}
return $subs ;
}
我的解決辦法是創建另一個函數從表removed_items
獲取記錄,並設置一個PHP條件其中I調用subscriptions_func()跳過/復位類似於在subscriptions_func(記錄中的記錄),如下面的
$sub = subscriptions_func($user_id);
foreach($sub as $sub){
$rmv_sub = rmv_items_func($sub[‘pic_id’]);
If($rmv_sub[‘pic_id’] != $sub[‘pic_id’]){
echo $sub[‘pic_id’];
}
}
將該溶液成功跳過的項目表中的removed_items
然而這種解決方案使得存儲在變量$子,這使得在迴盪項木板點陣列中的間隙。
是否有一個條件,我可以添加到函數subscriptions_func()來削減所有額外的條件和檢查?
這工作就像魅力,謝謝你,我會考慮你的額外建議。 – benjamin 2014-10-11 18:24:49
不客氣! – ForguesR 2014-10-11 18:25:41