Cookie を使用して mysql テーブルの値を選択するにはどうすればよいですか?
Cookie に応じて mysql テーブルの値を選択したかったのです。
私はこのクエリを持っています、
function db_prepare_input($string)
{
if (is_string($string)) {
return trim(stripslashes($string));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = tep_db_prepare_input($value);
}
return mysql_real_escape_string($string);
} else {
return mysql_real_escape_string($string);
}
}
$country_id = db_prepare_input($_COOKIE['country']);
$catglobal_sql = "select p.*, case when p.specials_new_products_price >= 0.0000 and p.expires_date > Now() and p.status != 0 then p.specials_new_products_price else p.products_price end price from " . TABLE_GLOBAL_PRODUCTS . " p INNER JOIN ".TABLE_STORES." s ON s.blog_id = p.blog_id where MATCH (p.products_name,p.products_description) AGAINST ('%".$search_key."%') OR p.products_name like '%".$search_key."%' and s.countries_id = '".$country_id."' and p.display_product = '1' and p.products_status = '1' ".$duration." order by p.products_date_added DESC, p.products_name";
$catglobal_1 = mysql_query($catglobal_sql);
Cookie はheader.php
ファイルに設定され、
<?php
if(!empty($_POST['country']))
{
$country = strtolower($_POST['country']);
setcookie("country", $country, time()+604800, '/'); // cookie expires in 7 days.
}
?>
でクエリを呼び出しますindex.php
。
たとえば、$_COOKIE['country']
値168
を選択したかったWHERE s.countries_id = '168'
ただし、Cookie の出力は空白です。そのためWHERE s.countries_id = ''
、値が返されません。
WHERE
節で Cookie を使用する方法を見つける必要があります