Solved

Passing row id into a url to display row data in new page

Posted on 2011-09-08
11
301 Views
Last Modified: 2012-05-12
Hi:

I am new to php programming.  I have a php page which displays data from the database in the form of a table.  In the table I have link.  

What I want is click on the link in the table row and display the row data in another page.

Thanks,

     view
0
Comment
Question by:adamssap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 20

Expert Comment

by:dsacker
ID: 36504601
You can easily make the link as follows:
He said at <a href="myReadMorePage.html" target="ReadMorePage">read more...</a>

Open in new window


That way, it will open up in it's own window (or separate tab), AND if they click on it again, it will simply refresh in the same window (or tab).
0
 
LVL 1

Author Comment

by:adamssap
ID: 36504630
I am sorry, I think I was not clear in my question.  I have a link already, but the link must open a new page wihin the same windows and display the row data from the database, which includes more fields.  
0
 
LVL 28

Expert Comment

by:strickdd
ID: 36504656
The link should be more like:

<a href="MyDetailsPage.php?RowId=<? echo $rowId ?>">read more...</a>

Then on the MyDetailPage.php, use the querystring value of RowId to pull the information.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:adamssap
ID: 36504673
Do you have an example?

Thanks,
0
 
LVL 28

Expert Comment

by:strickdd
ID: 36504697
in you code, where you are looping through and printing all the rows, add the row id to the href's target. Then create the details page that makes the database call for ONLY that row's data and displays it. If you can create the grid display, you can create the details display.
0
 
LVL 2

Expert Comment

by:shdwmage
ID: 36504737
code example:
foreach($variable1 as $value){
echo "<a href="MyDetailsPage.php?RowId=$value">read more...</a>";
}

Open in new window

0
 
LVL 1

Author Comment

by:adamssap
ID: 36504742
I got the idea.  As I said, I am new to php.  An example will be greatly appreciated.

Thanks.
0
 
LVL 28

Expert Comment

by:strickdd
ID: 36504793
Here is a pretty straight-forward how to on the topic. It will walk you through step-by-step: http://www.siteground.com/tutorials/php-mysql/database_connection.htm
0
 
LVL 8

Expert Comment

by:PranjalShah
ID: 36504846
When you click on the link read more, can you give the URL of that page? And please dont post redundant questions.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/HTML/Q_27294255.html
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 36504888
assuming that every record in your db has a unique id, then generate:
<a href="details.php?id={$row['id']}">read more...</a>

then on detail.php all you need is:
<?php

if( isset($_GET['id']) && !empty($_GET['id']) )
{
  mysql_connect('localhost','username','password') or die( mysql_error() );
  mysql_select_db('databaseName') or die( mysql_error() );
  $sql='SELECT * FROM TableName WHERE id='.mysql_real_escape_string($_GET['id']);
  $result=mysql_query($sql) or die('Unable to execute <br />'. htmlentities($sql,ENT_QUOTES). '<br />'. mysql_error() );

  while($row=mysql_fetch_assoc($result) ){
    //assuming you have a description field
    echo $row['description'];
  }
}
exit;
?>
0
 
LVL 1

Author Closing Comment

by:adamssap
ID: 36505183
Thanks a ton.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question