[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Passing variables between pages

Posted on 2004-09-21
3
Medium Priority
?
302 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 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

656 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