I'm creating a website for hotels and foods. The page is for registered members only. So, for unregistered users I created a demo of my site. In that demo, the page will show the hotels name(stored in the DB) as a table in the first page.
When they click the submit button next to the hotel name the next page should show the foods under that hotel name only.
Now, I have a problem. How can I pass the specific hotel id to the next function. Here are my codes, I've tried global, public everything.. nothing is working. I've tried to return that variable also, but there are some echos in my function. So, when I call the function the table is printed again.
I need to pass the $data['id'] to the next function to filter the food table.
Can anybody help me on this please...
First Function:
function print_all_hotels(){
$result = mysql_query("SELECT * FROM hotels "); // selecting data through mysql_query()
if (!$result) {
die("Database query failed: " . mysql_error());
}
echo '<table border=1px >'; // opening table tag
echo'<th><div style="width: 100px" ></div>No.</th>
<th><div style="width: 200px" ></div>Name</th>
<th><div style="width: 300px" ></div>Details</th>'; //table headers
while($data = mysql_fetch_array($result))
{
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$data['id'].'</td><td>'.$data['h_name'].'</td><td><form action="details.php" method="POST" style="margin-left:-30%; margin-bottom:-5%"><input style=" border:1px solid #000" class="login_submit" type="submit" name="submit" value="View Details!"></form></td>'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
echo '</table>'; //closing table tag
}
Second Function:
function print_all_foods(){
$counter =1;
$result = mysql_query("SELECT * FROM foods where /*Here is the problem*/"); // selecting data through mysql_query()
if (!$result) {
die("Database query failed: " . mysql_error());
}
echo '<table border=1px >'; // opening table tag
echo'<th><div style="width: 100px" ></div>No.</th>
<th><div style="width: 200px" ></div>Foods</th>'; //table headers
while($data = mysql_fetch_array($result))
{
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$counter++.'</td><td>'.$data['name'].'</td>'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
echo '</table>'; //closing table tag
}
session?