我似乎无法让它返回我想要的选项值。
我希望它运行的 sql 查询是:
SELECT `profile_value` FROM `login_profiles` WHERE `pfield_id` = 1 AND `user_id` = 1 LIMIT 1
我试过这个
<?php $profile->getOption('1', false, true, '1'); ?>
和没有引号的 id 一样,但它没有用。
/**
* Retrieves an option value based on option name.
*
* @param string $option Name of option to retrieve.
* @param bool $check Whether the option is a checkbox.
* @param bool $profile Whether to return a profile field, or an admin setting.
* @param int $id Required if profile is true; the user_id of a user.
* @return string The option value.
*/
public function getOption($option, $check = false, $profile = false, $id = '') {
if (empty($option)) return false;
$option = trim($option);
if ( $profile ) {
$params = array(
':option' => $option,
':id' => $id
);
$sql = "SELECT `profile_value` FROM `login_profiles` WHERE `pfield_id` = :option AND `user_id` = :id LIMIT 1;";
} else {
$params = array( ':option' => $option );
$sql = "SELECT `option_value` FROM `login_settings` WHERE `option_name` = :option LIMIT 1;";
}
$stmt = $this->query($sql, $params);
if(!$stmt) return false;
$result = $stmt->fetch(PDO::FETCH_NUM);
$result = $result ? $result[0] : false;
if($check)
$result = !empty($result) ? 'checked="checked"' : '';
return $result;
}
谢谢