Now, let make function flexible for usage in frontend and admin zone:
$frontend is an optional parametar for the above function, which means that function could be call with or without it. When it's called without it (in admin zone), it will assign false to $frontend by default.
function article_read($article_id, $frontend = false)
$sql = "SELECT article_name, summary, author, article_content, notes, date_added, status";
$sql .= " FROM articles";
$sql .= " WHERE articleID = '".$article_id."'";
$sql .= " AND Status = '1'";
$res = my_query($sql);
if(mysql_num_rows($res) != 0)
$num = mysql_fetch_assoc($res);
Now when calling funtion in frontend, we will call it this way:
This way we are sure that visitors don't have access to articles which are not approved.
$article = article_read($article_id, true)
This is also a good example for seeing purpose of writting functions.