Page 1 of 1
Show MySql content on page
Posted: Sat May 06, 2006 6:55 am
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?
Posted: Sat May 06, 2006 7:02 am
by feyd
try ` instead of ' for the table and field (column) references.
Posted: Sat May 06, 2006 9:32 am
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

Posted: Sat May 06, 2006 9:37 am
by feyd
'article' is a string, `article` is a database/table/column reference.
Posted: Sat May 06, 2006 10:01 am
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
Posted: Sat May 06, 2006 10:46 am
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
Posted: Sat May 06, 2006 10:48 am
by feyd
add a <br />, \n or combination thereof to the echo.
Posted: Sat May 06, 2006 11:02 am
by chrisso
OOOH !!

I see =D
Very very very thank you guys !