Page 1 of 1

pass variables to a db function

Posted: Fri Jul 04, 2003 9:11 am
by leeUK
Hi there peeps,
I am a beginner and have a question: i have a database with hotels listed per country. I have a function which i'd like to use for all countries. However each countries hotels will be listed on its seperate page.

So basically i have an .inc file which has the generic db query something like this:

function showHotel($whichCountry)
global $whichCountry;
{
blah blah blah dbquery WHERE country=$whichCountry.
}


// then i call the query like so on my page hotels_spain.php:
// es for spain
<?php
showHotel("es");
?>


This should then translate to WHERE country=es.
However the variable whichCountry is always empty when it's called. Any ideas, i know its something simple but can remember how ;-0
Thanx
Lee

Posted: Fri Jul 04, 2003 10:14 am
by CyberSpatium
Remove this from inside your function:

Code: Select all

global $whichCountry;
Using global inside your function invalidates whatever $whichCountry is set to, registers it as a global variable, and sets it to NULL. That is why $whichCounty is not being passed to your function.

Cyber