I have a function and can't make it work. I tried many things but still no luck.
function get_posts($id = null, $category_id = null) {
$posts = array();
$query = "SELECT `posts`.`id` AS 'post_id', `categories`.`id` AS 'category_id',
`title` , `content` , `date_posted` , `categories`.`name`
FROM `posts`
INNER JOIN `categories` ON `categories`.`id` = `posts`.`category_id`";
if (isset($id)) {
$id = (int)$id;
$query .= "WHERE `posts` . `id` = '{$id}'";
}
if (isset($category_id)) {
$category_id = (int) $category_id;
$query .= "WHERE `category_id` = '{$category_id}'";
}
$query .= "ORDER BY `posts` . `id` DESC";
$query = mysql_query($query);
while ($row = mysql_fetch_assoc($query)) {
$posts[] = $row;
}
return $posts;
}
How do I make it show only to the user who posted it, not to all the users. It's supposed to work like a diary.
