Solved

Passing variables between pages

Posted on 2004-09-21
3
289 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

696 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