Page 1 of 1

Displaying each record in its own webpage

Posted: Mon Nov 30, 2009 1:38 pm
by raquelm
Hello everyone. I'm trying to display each record of a mysql database in its own webpage. I read somewhere that this can be accomplished with a template by passing columnnames through a URL, but I can't find any documentation on how to do this. If anyone can give me tips, hints or point me in the right direction, I'd appreciate it. Thanks!

Re: Displaying each record in its own webpage

Posted: Mon Nov 30, 2009 1:56 pm
by pickle
A simple set up would be like this:

The url to the page being: http://www.mydomain.com/record.php?id=23

Code: Select all

$id = $_GET['id'];
$query = "SELECT * FROM `table` WHERE `id` = '$id'";
//get the results & echo them
Of course, there's a bit more to it than that - protection against SQL injection & all that - but that's the basic idea.

Re: Displaying each record in its own webpage

Posted: Mon Nov 30, 2009 2:54 pm
by raquelm
Pickle, thanks for the tip. I tried that code but keep getting a "Parse error: syntax error, unexpected T_ECHO"

Here's what how I wrote the code:

$id = $_GET['id'];
$query = "SELECT * FROM inventory WHERE `id` = '$id'";
/* get the results & echo them */
$result = mysql_query($query)
or die ("Couldn't execute query.")

/* display fields */
echo "$itemname";

Am I missing something?

Re: Displaying each record in its own webpage

Posted: Mon Nov 30, 2009 3:08 pm
by AbraCadaver
raquelm wrote:Am I missing something?
Yes, a semicolon ;

Re: Displaying each record in its own webpage

Posted: Mon Nov 30, 2009 3:45 pm
by raquelm
Got it, and it works perfectly, thanks!