Php Blog
Posted: Thu Dec 15, 2011 4:32 am
Hello i have some code i copied from the php blog tutorial that is not working. Any help is accepted.
<?php $connect = mysql_connect('localhost', 'root', 'root'); $databse = mysql_select_db(blog, $connect); echo mysql_error(); function valid_pid($pid) { $pid = (int)$pid; $total = mysql_query("SELECT COUNT(post_id) FROM posts WHERE post_id='$pid'"); $total = mysql_result($total, 0); if ($total !=1) { return false; } else { return else; } } function get_posts() { $sql = "SELECT posts.post_id AS id, posts.post_title AS title, LEFT(posts.post_body, 512) AS preview, posts.post_user AS user, DATE_FORMAT(posts.post_date, '%d/%m/%y %H:%i:%s') AS date, comments.total_comments, DATE_FORMAT(comments.last_comment, '%d/%m/%y %H:%i:%s') AS last_comment, FROM posts LEFT JOIN ( SELECT post_id, COUNT(comment_id) AS total_comments, MAX(comment_date) AS last_comment, FROM comments GROUP BY post_id ) AS comments ON posts.post_id = comments.post_id ORDER BY posts.post_date DESC"; echo mysql_error(); $posts = mysql_query($sql); $rows = array(); while (($row = mysql_fetch_assoc($posts)) !== false) { $rows[] = array( 'id' => $row['id'], 'title' => $row['title'], 'preview' => $row['preview'], 'user' => $row['user'], 'date' => $row['date'], 'total_comments' => (), 'last_comment' => () ); } } function get_post($pid) { } function add_post($name, $title, $body) { } echo 'Hello'; ?>