Displaying each record in its own webpage

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
raquelm
Forum Newbie
Posts: 3
Joined: Mon Nov 30, 2009 1:33 pm

Displaying each record in its own webpage

Post 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!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Displaying each record in its own webpage

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
raquelm
Forum Newbie
Posts: 3
Joined: Mon Nov 30, 2009 1:33 pm

Re: Displaying each record in its own webpage

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Displaying each record in its own webpage

Post by AbraCadaver »

raquelm wrote:Am I missing something?
Yes, a semicolon ;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
raquelm
Forum Newbie
Posts: 3
Joined: Mon Nov 30, 2009 1:33 pm

Re: Displaying each record in its own webpage

Post by raquelm »

Got it, and it works perfectly, thanks!
Post Reply