title: Passing SQL variable from one PHP to another PHP
body: <p>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.</p>
  
  <p>When they click the submit button next to the hotel name the next page should show the foods under that hotel name only.</p>
  
  <p>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.</p>
  
  <p>I need to pass the $data['id'] to the next function to filter the food table.</p>
  
  <p>Can anybody help me on this please...</p>
  
  <p>First Function:</p>
  
  <pre><code>function print_all_hotels(){
  
      $result = mysql_query("SELECT * FROM hotels "); // selecting data through mysql_query()
      if (!$result) {
          die("Database query failed: " . mysql_error());
      }
      echo '&lt;table border=1px &gt;';  // opening table tag
  
      echo'&lt;th&gt;&lt;div style="width: 100px" &gt;&lt;/div&gt;No.&lt;/th&gt;
      &lt;th&gt;&lt;div style="width: 200px" &gt;&lt;/div&gt;Name&lt;/th&gt;
      &lt;th&gt;&lt;div style="width: 300px" &gt;&lt;/div&gt;Details&lt;/th&gt;'; //table headers
  
      while($data = mysql_fetch_array($result))
      {   
          // we are running a while loop to print all the rows in a table
          echo'&lt;tr&gt;'; // printing table row
          echo '&lt;td&gt;'.$data['id'].'&lt;/td&gt;&lt;td&gt;'.$data['h_name'].'&lt;/td&gt;&lt;td&gt;&lt;form action="details.php" method="POST" style="margin-left:-30%; margin-bottom:-5%"&gt;&lt;input style=" border:1px solid #000" class="login_submit" type="submit" name="submit" value="View Details!"&gt;&lt;/form&gt;&lt;/td&gt;'; // we are looping all data to be printed till last row in the table
          echo'&lt;/tr&gt;'; // closing table row
      }
  
      echo '&lt;/table&gt;';  //closing table tag
  }
  </code></pre>
  
  <p>Second Function:</p>
  
  <pre><code>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 '&lt;table border=1px &gt;';  // opening table tag
  
      echo'&lt;th&gt;&lt;div style="width: 100px" &gt;&lt;/div&gt;No.&lt;/th&gt;
      &lt;th&gt;&lt;div style="width: 200px" &gt;&lt;/div&gt;Foods&lt;/th&gt;'; //table headers
  
      while($data = mysql_fetch_array($result))
      {
          // we are running a while loop to print all the rows in a table
          echo'&lt;tr&gt;'; // printing table row
          echo '&lt;td&gt;'.$counter++.'&lt;/td&gt;&lt;td&gt;'.$data['name'].'&lt;/td&gt;'; // we are looping all data to be printed till last row in the table
          echo'&lt;/tr&gt;'; // closing table row
      }
  
      echo '&lt;/table&gt;';  //closing table tag
  }
  </code></pre>