Link to home
Start Free TrialLog in
Avatar of dm_mcelduff
dm_mcelduffFlag for Australia

asked on

Passing variables between pages

Hi,
I am using the code below to display a table on a page with some information for a helpdesk. I want the user to have the ability to look at more detailed information on the incident by clicking the incident number. The link to the other page works using the code :
              echo '<td> <a href="details.php">'.$row['incidentno'].'</a></td>';   (for full code listing see below)

This link works but on the 'details.php' page I only want to show details of the incident selected by the user. I know that I need to pass a variable to the other page but how?

PHP code used on page:

<?php
  mysql_connect("localhost", "administrator", "password");
  echo '<table width="85%" border="1">';

echo '<tr><th>Incident Number</th><th>Type</th><th>Decription</th><th>Date</th><th>Engineer</th></tr>';  

$sql="SELECT incidentno, type, shortdesc, date, engineer FROM helpdesk.incidents WHERE status = 'Open'";
$result=mysql_query($sql);

if(mysql_num_rows($result)>0)
{
 
  while($row=mysql_fetch_assoc($result))  
  {
        
    echo '<tr>';
    echo '<td> <a href="details.php">'.$row['incidentno'].'</a></td>';
    echo '<td>'.$row['type'].'</td>';
    echo '<td>'.$row['shortdesc'].'</td>';
    echo '<td>'.$row['date'].'</td>';
    echo '<td>'.$row['engineer'].'</td>';
    echo '</tr>';

  }
}
else
{
  echo '<tr><td colspan="200">no data retieved</td></tr>';  
}
echo '</table>';
?>
ASKER CERTIFIED SOLUTION
Avatar of cLFlaVA
cLFlaVA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of llcooljayce
You can pass variables in the URL by simply adhering to this format:

<a href="mypage.php?VariableName=$VariableValue">Link</a>

To add more than one variable to pass simply use the & symbol.  For example:

<a href="mypage.php?name=$username&birthday=$dob">Link</a>

You can pass as many variables as you need to.  To access the variable value in the following php page simply refer to it as the VariableName (as in my first example).  Or in my second example:

echo "Hello there ".$name." welcome to my new page!";

Hope this helps.  Cheers.

Jayce
Avatar of dm_mcelduff

ASKER

Cheers cLFlaVA that worked a treat :)