Solved

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

Posted on 2011-09-08
11
302 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
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!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

632 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