Page 1 of 1

PHP Variables

Posted: Mon Aug 10, 2009 9:39 am
by jcfox412
Hi all, new to the site, hoping to solve a tricky variables problem.

So I have a mysql database that is storing customer data. I would like the have one php page (info.general.php) that displays a limited amount of information - the customer's ID, along with their first and last names. I would like to have the customerID column be a series of links to another php page (info.specific.php) that gives a more detailed account of the customer - perhaps address, phone number, etc. The problem is, since all of these links (in the customerID column) are leading to the same php page, namely info.specific.php, I have not found a way to pull up ONLY one specific customer's information - the one whose customerID i clicked on. In other words, I would need to pass information from one php page to another with a variable that is specific to that customerID, so that I could just add that add that restriction to my mysql_query. but the problem is, I don't know how to pass a php variable that is unique to each link - since that is the only action that is moving me from one php page to another, is there a way to associate a php variable to each individual link so that my info.specific.php page has a way to identify which link has been clicked on? Thanks for any information anyone has.

Code for info.general.php:

Code: Select all

<?php
$con = mysql_connect("flexo","jfox","password");
if(!$con)
{
    die('Could not connect: ' . mysql_error());
}
 
mysql_select_db("my_db", $con);
 
$result = mysql_query("SELECT * FROM form_requests");
 
echo "<table cellpadding='10' border='1'>
<tr>
<th>Customer ID</th>
<th>First name</th>
<th>Last name</th>
</tr>";
while($row = mysql_fetch_array($result))
    {
    echo "<td>" . "<a href=info.specific.php" . " name=" . $row['personID'] . ">" . $row['personID'] . "</a>";
    $customerID = array();
    $customerID[$row['personID']]=$row['personID'];
        echo "<td>" . $row['firstname'] . "</td>";
        echo "<td>" . $row['lastname'] . "</td>";
    echo "</tr>";
    }
echo "</table>"
mysql_close($con);
?>

Re: PHP Variables

Posted: Mon Aug 10, 2009 10:06 am
by aceconcepts
You can pass variables to other pages via the url:

Code: Select all

echo "<td>" . "<a href=info.specific.php?id=".$row['customerID']." . " name=" . $row['personID'] . ">" . $row['personID'] . "</a>";

Re: PHP Variables

Posted: Mon Aug 10, 2009 10:12 am
by jcfox412
Ahh that works beautifully. Thanks for the quick reply.