Hi, I am new to php. I am working on a product. My product has a search page, with multiple criteria. Next page will show the matched recodes (with some information) in a table format. Now I would like to show the details of a particular record, by clicking on a row, and the details will be shown in a new page.

I have done till the table generation. But I am unable to do the rest.

Please help me

Now I would like to show the details of a particular record, by clicking on a row, and the details will be shown in a new page

Assuming that each record has a unique id, all you need to do is:
for every row add a table cell that includes a <form> . It should include a hidden field with the product id for the row in question, it should "point" to the page where you will get the product details, and it should have its own Edit button.

Ultimately, your table should be similar to the following (where pid is the product id for the row in question):

<tr><td>row 1 cell 1</td><td>row 1 cell 2</td><td>...</td><td><form method="post" action="yourEditPage.php"><input type="hidden" name="pid" value="3"/><input type="submit" name="editRow" value="Edit"/></form></td></tr>
<tr><td>row 2 cell 1</td><td>row 2 cell 2</td><td>...</td><td><form method="post" action="yourEditPage.php"><input type="hidden" name="pid" value="31"/><input type="submit" name="editRow" value="Edit"/></form></td></tr>

Assuming that each record has a unique id, all you need to do is:
for every row add a table cell that includes a <form> . It should include a hidden field with the product id for the row in question, it should "point" to the page where you will get the product details, and it should have its own Edit button.

Ultimately, your table should be similar to the following (where pid is the product id for the row in question):

<tr><td>row 1 cell 1</td><td>row 1 cell 2</td><td>...</td><td><form method="post" action="yourEditPage.php"><input type="hidden" name="pid" value="3"/><input type="submit" name="editRow" value="Edit"/></form></td></tr>
<tr><td>row 2 cell 1</td><td>row 2 cell 2</td><td>...</td><td><form method="post" action="yourEditPage.php"><input type="hidden" name="pid" value="31"/><input type="submit" name="editRow" value="Edit"/></form></td></tr>

Thanks for your reply. It helped me a lot. But I don't have a fixed value, instate of that I have a variable, and I would like to pass that as a value.

Here's a quicker way.
Suppose this is your table.
+--+----+-------
|id|name|stuff ..
++++++++++++++++
You could make ID clickable by doing:

<a href="newpage.php?id=<?php echo $row['id']; ?>"><?php echo $row['id']; ?></a>

This will send ID as a GET value to newpage.php (without the form; using a form will CONFUSE your code in this case). In newpage.php you can access that value by using $_GET.
Hope this helps.

But I don't have a fixed value, instate of that I have a variable, and I would like to pass that as a value.

Of course you don't. I did not post PHP. I posted a sample html code/result of what YOUR PHP code should generate. In other words, after your page loads up, that is what you should see if you look at your browser's source code. I was expecting you to realize that:
a. each row of

<tr>...</tr>is generated from within a while construct - that is when you are iterating over the records of your db query result

b. Instead of
... value="3"... you would actually need to put the variable you are using for extracting the relevant value from your db query.

...
$result=mysql_query("SELECT id, email FROM Person") or die( mysql_error() );
if( mysql_num_rows($result) ==0 )
{
  echo 'No Records found';
}
else
{
 echo '<table>';
  while( $row = mysql_fetch_assoc($result))
  {
    echo sprintf('<tr><td>%s</td><td><form method="post" action="yourEditPage.php"><input type="hidden" name="pid" value="%s"/><input type="submit" name="editRow" value="Edit"/></form></td></tr>', $row['email'], $row['id']);
  }
 echo '</table>';
}

Thanks for all the reply. I have also figured that, and my problem is over.
Thanks again for your response and time.

You could mark the thread as solved now ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.