Jump to content


Photo

Display selected record that has been passed to URL


  • Please log in to reply
6 replies to this topic

#1 slack

slack
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 March 2006 - 05:14 PM

[!--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--]

#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 10 March 2006 - 05:24 PM


[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...

#3 slack

slack
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 March 2006 - 06:41 PM

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.

$RID = $_GET['recordID'];

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

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


#4 slack

slack
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 March 2006 - 08:26 PM

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

To solve I did something like this:

$RID = $_GET['recordID'];

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

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

This will now display the selected title

#5 tjmaxwell

tjmaxwell
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 March 2006 - 04:20 AM

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:

<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>

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!

#6 tjmaxwell

tjmaxwell
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 March 2006 - 04:02 AM

Anybody?

#7 abe_sapien1

abe_sapien1
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 March 2006 - 06:22 AM

Hi there,

It appears you arent defining those values correctly. try this


$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>


best of luck to ya hope that helped




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users