Having empty string from returning in PHP
When I use some characters like / in the textbox I get returned an empty string in response. I can easily make a check for empty string in my html but my question is how can I avoid having that empty string from being sent over in my php code?
$("#search").keyup(function(){
var newVal = $(this).val();
if(!newVal==""){
$.ajax({
type : 'get',
dataType: 'html',
url : '/searchpost/' + newVal ,
success : function(response) {
console.log(response);
}
});
}
});
public function searchpost() {
$q = $this->uri->segment(3);
if(!$q) die();
$string = trim(strip_tags($q));
$db_string = urldecode($string);
$this->db->select("postID, post_title, post_url, post_status");
$this->db->like("post_title", $db_string);
$this->db->or_like("post_url", $db_string);
$posts = $this->db->get('posts', 10);
if(!count($posts->result())) {
die('Nothing to display');
}
?>
result() as $m) :
if($m->post_status != 'active' OR empty($m->post_title)) continue;
?>
-
post_url; ?>