Show MySql content on page

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
chrisso
Forum Newbie
Posts: 10
Joined: Sat May 06, 2006 6:50 am

Show MySql content on page

Post by chrisso »

Hi

I'm bulding a webside without a very good knowledge of MySql.
And in the blogg/news I want to show the content from the "article" table on my mysql db.
I thought it would be something like this:

Code: Select all

$query = "SELECT * FROM 'article' ORDER BY 'aid' DESC";
....etc...
Can anyone help me, plz?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try ` instead of ' for the table and field (column) references.
chrisso
Forum Newbie
Posts: 10
Joined: Sat May 06, 2006 6:50 am

Post by chrisso »

Didn't understand that.

Well, I have a table called 'article' with the following fields: aid, author, time, content.
And how can I display the 10 latest rows/articles from that table on the website?

Thank you :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

'article' is a string, `article` is a database/table/column reference.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You're using single quotes when you should be using a backtick (i think that's what its called)

single quote = '
backtick = `

so therefore

'articles' should be `articles`

and to display the 10 latest articles

Code: Select all

$result = mysql_query("SELECT * FROM `articles` ORDER BY `id` DESC LIMIT 10") or die(mysql_error());
while($array = mysql_fetch_assoc($result)){
   echo $array['text'];
}
for example
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
chrisso
Forum Newbie
Posts: 10
Joined: Sat May 06, 2006 6:50 am

Post by chrisso »

I'm really thankful for the help. :)

I'm now able to show the content on the page, but now I need to divide each row(/content) from each other.
It is several articles, and now the page looks like this:
News1News2News3News4
It should look like this (with a title):
News1

News2

News3

News4
You see?


Thank you in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

add a <br />, \n or combination thereof to the echo.
chrisso
Forum Newbie
Posts: 10
Joined: Sat May 06, 2006 6:50 am

Post by chrisso »

OOOH !! ;) I see =D

Very very very thank you guys !
Post Reply