Solved

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

Posted on 2011-09-08
11
289 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
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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now