开发者

How to display a members info and articles to a visitor using PHP and MySQL?

开发者 https://www.devze.com 2022-12-11 06:03 出处:网络
I was wondering how can I display a members article they created and show it to visitors all while displaying the members info that is associated with that article to the visitors.

I was wondering how can I display a members article they created and show it to visitors all while displaying the members info that is associated with that article to the visitors.

I hope I explained it right?

Here is my mysql articles table.

CREATE TABLE authors_articles (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
author_id INT UNSIGNED NOT NULL,
title TEXT NOT NULL,
summary TEXT DEFAULT NULL,
content LONGTEXT NOT NULL,
date_created DATETIME NOT NULL,
date_updated DATETIME DEFAULT NULL,
PRIMARY KEY (id)
);

Here is my authors table.

CREATE TABLE author (
id INT NOT NULL开发者_如何学运维 AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255)
) DEFAULT CHARACTER SET utf8;

For example an author creates an article it displays all the info the author entered when finished but how do I make it display for visitors who visit the articles page? Do I do it by the url?


say you are on a page showing a member's article(with article id in php variable $article_id) and you want to show that member's information, you would need to write a simple join query:

select * from authors_articles,author where
authors_articles.id = $article_id
and authors_articles.author_id = author.id

if you are on a member's profile page(with member's id in php variable $author_id) and want to show information, link to last few article's by that member, the query would be:

select author.id,author_articles.id, title,summary,date_created,name,email from 
author,authors_articles  where author.id = authors_articles.author_id
and author.id = $author_id  LIMIT 5
0

精彩评论

暂无评论...
验证码 换一张
取 消