function prepare_search_table search_params db if is_null db is_object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function prepare_search_tables($search_params, $db)
{
if (is_null($db) || !is_object($db) || (get_class($db) != 'DatingDB'))
{
trigger_error("Incorrect database object", E_USER_ERROR);
return;
}
if ($search_params['incoming_winks'])
{
$db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS incoming_winks_search (from_id INT NOT NULL)");
$db->Execute("TRUNCATE incoming_winks_search");
$db->Execute("INSERT incoming_winks_search SELECT from_id FROM winks WHERE to_id=:i:to_id:", array('to_id' => current_user_id()));
$db->Execute("ALTER TABLE incoming_winks_search ENGINE MEMORY");
}
if ($search_params['outgoing_winks'])
{
$db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS outgoing_winks_search (to_id INT NOT NULL)");
$db->Execute("TRUNCATE outgoing_winks_search");
$db->Execute("INSERT outgoing_winks_search SELECT to_id FROM winks WHERE from_id=:i:from_id:", array('from_id' => current_user_id()));
$db->Execute("ALTER TABLE outgoing_winks_search ENGINE MEMORY");
}
if ($search_params['who_viewed'])
{
$sub_sql = "CREATE TEMPORARY TABLE IF NOT EXISTS `profiles_activities_search`
(
`id` int NOT NULL,
`tdate` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
if($db->execute($sub_sql))
{
$db->execute("TRUNCATE TABLE `profiles_activities_search`");
$sub_sql = "INSERT IGNORE INTO profiles_activities_search (id, tdate)
(SELECT pa.from_id, pa.tdate FROM profiles_activities as pa WHERE pa.from_id <> pa.to_id and pa.to_id= " . intval($_SESSION['MEMBER']['id']) . "
AND DATEDIFF(curdate(),DATE(FROM_UNIXTIME(pa.tdate)))<=14 and sentbrowse = 1)
UNION
(SELECT pa.to_id, pa.tdate FROM profiles_activities as pa WHERE pa.from_id <> pa.to_id and pa.from_id= " . intval($_SESSION['MEMBER']['id']) . "
AND DATEDIFF(curdate(),DATE(FROM_UNIXTIME(pa.tdate)))<=14 and gotbrowse = 1)";
$db->execute($sub_sql);
$db->execute("ALTER TABLE profiles_activities_search ENGINE MEMORY");
}
unset($_SESSION['SESSION']['LAST_FSEARCH_SQL']);
}
}