pass variables to a db function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leeUK
Forum Newbie
Posts: 1
Joined: Fri Jul 04, 2003 9:11 am

pass variables to a db function

Post 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
CyberSpatium
Forum Newbie
Posts: 21
Joined: Thu Mar 20, 2003 12:23 pm
Contact:

Post 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
Post Reply