我有城市,生日和用户表。 现在,我想要做的是通过数据库查询和过滤年龄和生活城市的范围(在所选地区的城市列表中 - 这就是我检查是否计数($ city []))&gt ; = 1),并根据uid / entety_id精细地提取用户名。 首先,我检查用户是否匹配年龄范围,然后检查他是否住在选定列表中的一个城市。 如果没有选择城市,我只想过滤年龄范围。
我不知道问题是什么,但据我所知, 有这个循环,我注意到根本没有执行:
for ($d = 1; $d < (count($the_resaults_array)); $d++)
这是代码:
function toodate_query_db($loest_age, $highest_age, $city){
$sql_user_name = '';
if((count($city[0]))>=1){
for ($i = 0; $i < count($city); $i++) {
$city_item_for_check = $city[$i];
$sql = "SELECT field_data_field_birth_date.entity_id
FROM field_data_field_birth_date, field_data_field_city
WHERE(
(field_birth_date_value >= DATE_ADD(NOW(), INTERVAL -{$highest_age} YEAR))
AND
(field_birth_date_value <= DATE_ADD(NOW(), INTERVAL -{$loest_age} YEAR))
AND
(field_city_tid = {$city_item_for_check})
AND
(field_data_field_birth_date.entity_id = field_data_field_city.entity_id))";
if(db_query($sql)->fetchColumn()){
$the_resaults_array[$i] = db_query($sql)->fetchAll();
}
}
for ($d = 1; $d < (count($the_resaults_array)); $d++) {
$user_id = $the_resaults_array[$d];
$sql_user_name .= '<p><strong>'.
db_query("SELECT name FROM {users} WHERE uid = {$user_id}")->fetchColumn()
.'</p></strong>';
}
} else{
$sql = "SELECT field_data_field_birth_date.entity_id
FROM field_data_field_birth_date
WHERE
field_birth_date_value >= DATE_ADD(NOW(), INTERVAL -{$highest_age} YEAR)
AND field_birth_date_value <= DATE_ADD(NOW(), INTERVAL -{$loest_age} YEAR)";
foreach (db_query($sql) as $result) {
$entity_id = $result->entity_id;
$sql_user_id = db_query("SELECT uid FROM {profile} WHERE pid = {$entity_id}")->fetchColumn();
$sql_user_name .= '<p><strong>'.
db_query("SELECT name FROM {users} WHERE uid = {$sql_user_id}")->fetchColumn()
.'</p></strong>';
}}
return $sql_user_name;
}