Solved

Passing variables between pages

Posted on 2004-09-21
3
295 Views
Last Modified: 2008-03-17
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>';
?>
0
Comment
Question by:dm_mcelduff
[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
3 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 125 total points
ID: 12117864

Make your while statement like this:

  while($row=mysql_fetch_assoc($result))  
  {
       
    echo '<tr>';
    echo '<td> <a href="details.php?id=' . $row['incidentno'] . '">'.$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>';

  }

Then, in your details.php page, use this code and SQL Statement:

# if the id is set in the url, use it, otherwise use 0
$ino = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;
$sql="SELECT incidentno, type, shortdesc, date, engineer FROM helpdesk.incidents WHERE incidentno = '" . $ino . "'";



Any more questions, feel free to ask...
0
 
LVL 4

Expert Comment

by:llcooljayce
ID: 12118815
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
0
 
LVL 2

Author Comment

by:dm_mcelduff
ID: 12125070
Cheers cLFlaVA that worked a treat :)
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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