Forum Moderators: coopster

Message Too Old, No Replies

PHP & MySQL fetching problem

         

Gero_Master

2:32 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Hello!

I concidered starting new website as a part of my "business". It is about commenting and reviewing devices like VCR, camcorders, phones, DVD, computers and lot else.

Problem is that i planned to make database like:

database
- laitekatsaus_articles
-- COLUMNS: id, email, name, date, ip, rating...
- laitekatsaus_comments (these are comments for users articles)
-- COLUMNS: id, articleid, name, date, ip...

I plannes to make it list the article names to a list. All those article names are links leading to the full articles. so... if there is article name in the list... lets say article id 1.

It has a link <a href="MYURL/viewarticle.php"></a>
How do i need to modify that if i want it to print on screen ONLY the row that has the id of the link in table LAITEKATSAUS_ARTICLES.

Should it be like <a href="MYURL/viewarticle.php?id=1"></a>

If it is like that, what do i need to do for the viewarticle.php's mysql query?

All help is appreciated

RonPK

4:30 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php 
// include your script with the db connection
require_once('db_connect.php');

if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$rs = mysql_query("SELECT *
FROM laitekatsaus_articles
WHERE id = $_GET[id]");
// rest of the script

It's probably easiest to get the comments in a separate query.

Anyway, I hope I'm not being rude, but it sounds like you could need a starters course in PHP and MySQL. Buy a book, Google for 'php tutorial', and dig through the archives of this forum!

Gero_Master

2:21 pm on Oct 7, 2005 (gmt 0)

10+ Year Member



No, not at all. Actually i have bought a book, but i havent read it further ;)

That tip was good, shall i include it to mysql query or the php code? And should i add my mysql data over to the db_conect include tag?

RonPK

9:56 am on Oct 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure what you mean here. The PHP code builds the MySQL query.

Most people find it handy to have one file that handles the connection to the database - mysql_connect() - and the selection of the database - mysql_select_db(). Simply include it when necessary, and you won't have to bother with remembering passwords et cetera.