Page 1 of 1

linking to a row to carry it's information over

Posted: Mon Jun 13, 2005 6:37 pm
by Fusioned
Howdy again peeps, this time I'm puzzled on how I'd get a

Code: Select all

$row['id'];
to be hyperlinked. Here's the deal:

Database is called and is told to give a list of all stores related to a college. It spits em out. Then, the user should be able to click on the store's name which by doing so, says: "Hey, I'm 7-Eleven and my Unique ID is 5. Carry over 5 to the next page so that all the items related to store 5 (that's me!) are displayed."

That's the best I can explain it. Here's the code:
university.php

Code: Select all

<?php


///Connection Stuff
$host = "localhost";
$user = "user";
$pass = "pass";
$db = "food";
$table = "places";
mysql_connect ($host,$user,$pass) or die ( mysql_error ()); 
mysql_select_db ($db)or die ( mysql_error ()); 

$query = "select places.* from schools, places where places.pid = '$school' AND  places.pid = schools.pid";
$result = mysql_query($query)
or die(mysql_error());
?>
<table cellspacing="2" cellpadding="2">
<tr> <td>Name</td> <td>Address</td> <td>Hours</td><td>PID</td></tr>
<?php
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";

echo $row['name'];
echo "</td><td>";
echo $row['address'];
echo "</td><td>";
echo $row['hours'];
echo "</td><td>";
echo $row['id'];
echo "</td></tr>";
}
echo "</table>";


?>
then the next page which displays the items is store.php

Code: Select all

<?php

echo "$store";

///Connection Stuff
$host = "localhost";
$user = "user";
$pass = "pass";
$db = "food";
$table = "items";
mysql_connect ($host,$user,$pass) or die ( mysql_error ()); 
mysql_select_db ($db)or die ( mysql_error ()); 

$query = "select items.* from places, items where items.pid = $store";
$result = mysql_query($query)
or die(mysql_error());
?>
<table cellspacing="2" cellpadding="2">
<tr> <td>Item</td> <td>Category</td></tr>
<?php

while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['category'];
echo "</td></tr>";
}
echo "</table>";

?>
The variable $store is supposed to be the Unique ID of the store. So that way the database checks which store it is, and displays the items for that specific store.

Thanks for all help in advance.

Posted: Mon Jun 13, 2005 10:49 pm
by wyred
You can pass variables through URLs, here's an example. This is how you print it out in university.php:

Code: Select all

echo '<a href="store.php?id='.$row['id'].'">'.$row['id'].'</a>';
And this is how you grab that id value in store.php

Code: Select all

$store = $_GET['id'];