$data['subject'] = "Music > Cello";
或
$data['subject'] = "cello";
$array = array();
if (strpos($data['subject'], '>') != FALSE)
{
$array = explode(' > ', $data['subject']);
$array[0]; // Music
$array[1]; // Cello
$subject = $array[1];
$catname = $array[0];
}
else
{
$subject = $data['subject'];;
}
//除非我刷新页面,否则会多次插入相同的数据。
$sql="INSERT INTO search_history(place,budget,subject,level,datetime)VALUES('$location','$o_rate','$subject','$catname', now())";
$stmt =connection::$pdo->prepare($sql);
$stmt->execute();
为了防止我尝试的重复条目:
1)获取数组中的最后一项
end($subject)<br/>
end($catname)<br/>
end($array)<br/>
2)
initialize array
$array =array();
3)
unset($array);<br/>
unset($subject);<br/>
unset($catname);<br/>