Jump to content

Display selected record that has been passed to URL


slack

Recommended Posts

[!--sizeo:2--][span style=\"font-size:10pt;line-height:100%\"][!--/sizeo--][!--fonto:Arial--][span style=\"font-family:Arial\"][!--/fonto--]Hello all,

I have a page which can list all records from a table in my local database.

For each record that is displayed there is link next to it. When the link is pressed another page opens up and the ID (automated primary key in my table) of the record selected is passed to the URL.

So now the URL looks something like this:

[a href=\"http://localhost/Webpages/newpage.php?recordID=3\" target=\"_blank\"]http://localhost/Webpages/newpage.php?recordID=3[/a]

How do I display the details of the record that has been selected on this new page?

Any help much appreciated!

Thanks
Slack[!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--]
Link to comment
Share on other sites


[a href=\"http://localhost/Webpages/newpage.php?recordID=3\" target=\"_blank\"]http://localhost/Webpages/newpage.php?recordID=3[/a]

$RID=$_GET['recordID'];

then do this query:

select * from table where recordID = '$RID'


Sorry, if you need a better answer let me know, I just got called to a meeting...
Link to comment
Share on other sites

Thanks for the quick reply.

It sounds easy from what you have stated but I still can't seem to get it to work.

I think it may be something to do with my select statement. Here is a sample of the code.

[code]$RID = $_GET['recordID'];

$query = "SELECT * FROM dvd WHERE id = '$RID'";
$result = mysql_query($query);
print ("$result[title]");[/code]

Just to let you know that the table is called 'dvd' and 'id' and 'title' are column names in my table.

I am just trying to display the 'title' of the selected record.

Thanks
Slack
Link to comment
Share on other sites

No need for a reply as I have worked out the problem.

To solve I did something like this:

[code]$RID = $_GET['recordID'];

$query = "SELECT * FROM `dvd` WHERE `id`='$RID'";
$result = mysql_query($query);

$row = mysql_fetch_array($result);
echo $row[title];[/code]

This will now display the selected title
Link to comment
Share on other sites

  • 2 weeks later...
Hello.

Sorry to resurrect an old topic, but this is the same kind of thing I'm trying to do. I've searched this forum and have found a couple of code samples, but I can't get them to work. Here's what I have so far:

[code]<html>
<body>
<?php
// listing script

// connect to the server
mysql_connect( 'localhost', 'user', 'pass' )
or die( "Error - Could not connect to database: " . mysql_error() );

// select the database
mysql_select_db( 'dbname')
or die( "Error! Could not select the database: " . mysql_error() );

$RID = $_GET['ID'];

$query = "SELECT * FROM `model_numbers` WHERE `ID`='$RID'";
$result = mysql_query($query);

$row = mysql_fetch_array($result);
echo $row[title];

?>
<table border="1" cellpadding="3" cellspacing="3">
<tr>
<th align="left">Manufacturer</th>
<td align="left"><?php echo($Manufacturer) ?></td>
</tr>
<tr>
<th align="left">Warranty</th>
<td align="left"><?php echo($Warranty) ?></td>
</tr>
<tr>
<th align="left">Weight</th>
<td align="left"><?php echo($Weight) ?></td>
</tr>
</table>

</body>
</html>[/code]

I have a product database that contains about 40 fields, and about 15 columns per product. I was trying this code without success. I'm very new to PHP and was wondering if when you select all records, you need to display them all at once? In other words, are my scripts not working because I'm only displaying three of the columns? Any help to get this working would be much appreciated. I want to create one PHP page that is dynamically populated based on the ID field. I want users to be able to go to www.domain.com/products.php?id=(number). Thanks a lot!
Link to comment
Share on other sites

Hi there,

It appears you arent defining those values correctly. try this


[code]$row = mysql_fetch_array($result);
echo $row['title'];  <-- notice the quotes

?>

<?php   # I am assuming below your column titles are 'Manufacturer' and 'Warranty' etc ...            ?>

<table border="1" cellpadding="3" cellspacing="3">
<tr>
<th align="left">Manufacturer</th>
<td align="left"><?php echo($row['Manufacturer']) ?></td>
</tr>
<tr>
<th align="left">Warranty</th>
<td align="left"><?php echo($row['Warranty']) ?></td>
</tr>
<tr>
<th align="left">Weight</th>
<td align="left"><?php echo($row['Weight']) ?></td>
</tr>
</table>[/code]


best of luck to ya hope that helped
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.