moos3
03-21-2008, 05:10 PM
not sure if this is the best way to check for nothing returned
$post[] = array();
$q = "SELECT title,body,author_id,id,cat_id FROM posts WHERE slug='$slug'";
$rs = mysql_query($q);
if(mysql_num_rows($rs) == 0){
$post = NULL;
}
else{
while($rw = mysql_fetch_array($rs)){
$post['title'] = $rw['title'];
$post['body'] = $rw['body'];
$post['author'] = $this->getAuthor($rw['author_id']);
$post['post_id'] = $rw['id'];
$post['category'] = $this->getCategory($rw['cat_id']);
}
}
return $post;
Right now i'm checking if mysql_num_rows is equal to zero. if so set $post array to NULL. Is this the best way do this?
$post[] = array();
$q = "SELECT title,body,author_id,id,cat_id FROM posts WHERE slug='$slug'";
$rs = mysql_query($q);
if(mysql_num_rows($rs) == 0){
$post = NULL;
}
else{
while($rw = mysql_fetch_array($rs)){
$post['title'] = $rw['title'];
$post['body'] = $rw['body'];
$post['author'] = $this->getAuthor($rw['author_id']);
$post['post_id'] = $rw['id'];
$post['category'] = $this->getCategory($rw['cat_id']);
}
}
return $post;
Right now i'm checking if mysql_num_rows is equal to zero. if so set $post array to NULL. Is this the best way do this?