hyperlink to dynamically retrieved data in a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

hyperlink to dynamically retrieved data in a table

Post by ishakya »

I'm new to php and i need to give an hyperlink to a data which is retrieved to a dynamically created data.Data means, table data.By that hyperlink,the user can be view the details of the selected value.
Eg: Assume a user select the hyperlink of a name of a person & once click the hyperlink,user can see the details of that person.I created the dynamic part & cannot proceed further.Please help me to proceed.... :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: hyperlink to dynamically retrieved data in a table

Post by social_experiment »

Pass the value in a query string page.php?name=Peter. To use it, access it through $_GET['name'].
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

Re: hyperlink to dynamically retrieved data in a table

Post by ishakya »

Thanks for your support.
But that doesn't support my problem.wait i'l paste the code.

Code: Select all

if (isset($_POST['search'])){
	/*{print_r($_POST);}*/ 
			
	 
	  $tx=$_POST['sea'];
	  
	  
$result =mysql_query("select * from strdet where styid  LIKE '%$tx%' || styname LIKE '%$tx%' || odrno ='$tx' ||  odrdet LIKE '%$tx%' || date LIKE '%$tx%' || merch LIKE '%$tx%' || gen LIKE '%$tx%' || taxt  LIKE  '%$tx%' ");

//$result =mysql_query("select * from strdet where odrno ='$tx'");
if (($result)||(mysql_errno == 0))
{
    echo "<table width='100%' border='0' cellspacing='5'><tr>";
  if (mysql_num_rows($result)>0)
  {
          //loop thru the field names to print the correct headers
          $i = 0;
          while ($i < mysql_num_fields($result))
          {
       echo "<th>". mysql_field_name($result, $i) . "</th>";
       $i++;
    }
    echo "</tr>";
   
    //display the data
    while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
    {
      echo "<tr>";
      foreach ($rows as $data)
      {
        echo "<td align='center'>". $data . "</td>";
      }
    }
  }else{
    echo "<td align='center'>No Results found</td></tr>";
  }
  echo "</table>";
}else{
  echo "Error in running query :". mysql_error();
}
	}
?>
this code creates the table dynamically and retrieve data from the table.Data is retrieved by a select query.but i need to place a href to a single data to view full details of the selected one.
Hope this will understand the story to u.Cheers!!!!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: hyperlink to dynamically retrieved data in a table

Post by social_experiment »

ishakya wrote:but i need to place a href to a single data to view full details of the selected one.
What i understand from this is : You display ALL results that matches your query. You want these values that are displayed to be a href (also now as a link or a hyperlink). So if you retrieved 'pumpkin' from the database you want something like this

Code: Select all

<table>
<tr><th>Field</th></tr>
<tr><td><a href="page.php?value=Pumpkin" >Pumpkin</a></td></tr>
</table>
Now if someone clicks on the link, they will go to a page that displays information about pumpkin.
If this is what you have in mind, the code below serves as an example on how to achieve this

Code: Select all

<?php
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
    {
      echo "<tr>";
      foreach ($rows as $data)
      {
        echo '<td align="center"><a href="pageName.php?value='. $data .'">'. $data .'</a>';
        // this produces a link with the value of $data in the query string.
      }
    }
 }
?>
Once this is in place, the first example of code i gave you should help you with retrieving the information. Hth.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ishakya
Forum Commoner
Posts: 40
Joined: Tue Jan 04, 2011 4:58 am

Re: hyperlink to dynamically retrieved data in a table

Post by ishakya »

Thanks social_experiment,
but let me explain further,
According to the select query,user can enter different searching conditions.according to that results will be changed.So table structure is same but data is different.

Code: Select all

$result =mysql_query("select * from strdet where styid  LIKE '%$tx%' || styname LIKE '%$tx%' || odrno ='$tx' ||  odrdet LIKE '%$tx%' || date LIKE '%$tx%' || merch LIKE '%$tx%' || gen LIKE '%$tx%' || taxt  LIKE  '%$tx%' ");
Assume user enter gender as his condition,following results are displayed.
styid styname
sfsf hj
ada c

So after that if he click on sfsf,he should see the details of sfsf within the same page.Just like a pop up.Within that pop up user can update details.
But the question is,how should i do that?
foolowing section is used to print data

Code: Select all

 if (mysql_num_rows($result)>0)
  {
          //loop thru the field names to print the correct headers
          $i = 0;
          while ($i < mysql_num_fields($result))
          {
       echo "<th>". mysql_field_name($result, $i) . "</th>";
       $i++;
    }
    echo "</tr>";
   
    //display the data
    while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
    {
      echo "<tr>";
      foreach ($rows as $data)
      {
        echo "<td align='center'>". $data . "</td>";
      }
    }
  }else{
    echo "<td align='center'>No Results found</td></tr>";
  }
  echo "</table>";
}
@where should i do?
Hope i explained which is in my mind.
Cheers again for your help!!!!!!!!!!!!!! :P
Post Reply