Simple blog post function

How would I create a simple blog posting function in PHP? I have a mySQL database with the following…

Table bloggers: id, name

Table posts: blogger id, post, timestamp

In plain English I want to display all posts with the blogger’s name (by matching the id with blogger id) and a timestamp, and the posts ordered by the timestamp to have the most recent ones first.

My current endeavours of selecting each one nested within the other isn’t working and I think I need to rethink the whole approach.

Simple model of blog post

I want to have a site that is a simple blog so I created a model: class Post < ActiveRecord::Base attr_accessible :title, :body end I want to use Markdown but without HTML tags. I also want alway

Simple PHP blog: Can’t edit post

BACKGROUND: So, I’ve been following this tutorial on how to build your own simple blog/CMS using PHP and MySQL on Youtube. The CMS lets you add categories, add posts, view category list and delete and

Blog post preview – wordpress

How can I add a preview to a blog post to a blog page? For example something like this on the blog page: Post name Date Picture Preview Read more Then on the blog post page: Post name Date Picture Blo

Why does the by() function not work in the way described in this blog post

I am trying to reproduce the analysis given in this blog post for the by() function. When I paste the code into R I get an error message, however, instead of the nice table of summarised iris data on

Django Blog Post Image

Added a featured image class which adds the ability to set a featured image for a blog post. class PostFeaturedImage(models.Model): last_modified = models.DateTimeField(auto_now_add=True,editable=Fals

Blog Post with Pictures?

In an effort to learn more about php and mysql, I have been working through a number of different tutorials and posts on building a simple blog site. I have a database that holds the necessary, usual

How to show a particular post for the logged in user in a simple blog site?

The scenario is, I have simple Post table with just title & story. after posting a new post I want to show the post using my view page.I have write the method to display the post as follows: //P

Simple Rails 3 blog

I have an app that I would like to add a blog to. I’d like to integrate it with my current site. I only have a few simple requirements: Being able to add formatting (headers, paragraphs, etc..) Addin

simple javascript AJAX post function not working

Hi I want to send data to the server and then have the php file save it. But currently I can’t get even a simple POST to work. This is the javascript and html part: This function is declared in the he

Drupal: Creating a simple blog?

I’m new to Drupal and trying get my head around it. I’d like to create a simple blog where I have a page that displays blog posts and the number of comments on each posts. Once the blog title or comme

Answers

try sql:

select * from bloggers A, posts B WHERE A.bloggerid = B.bloggerid 

I’d suggest you read up on the basics of SQL as this seems pretty straightforward:

SELECT 
   b.name, p.post, p.timestamp
FROM
   posts p
INNER JOIN
   bloggers b
ON 
   p.blogger_id = b.id
WHERE
   b.blogger_id = :id
ORDER BY
   p.timestamp DESC

Note that the :id part above is for use in a prepared statement, described below.

As for the PHP function, you should use PDO for this.

I may not quite understand how you’re organizing things but…

Assuming you can get the author’s id by selecting the bloggers table and getting the id you want you could do something like this:

$result = mysql_query("SELECT * FROM posts WHERE blogger_id='" . $author_id . "' ORDER BY timestamp DESC") or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
 echo '<div class="post"><div class="time">' . $row['timestamp'] . '</div><div class="content">'. $row['post'] .'</div></div>';
}