Hi there guys,
Well, during the time alloted to me, I tried to implement this on my own, but am having a problem:
Page being loaded:
// bg type: 1) Finished 2) Under Construction 3) Both
$bg_type = '3';
/*We need to determine which templates are available for this page in particular*/
if(!ISSET($_GET['bg_id'])){
$bg_id='999';
}else{
$bg_id = $_GET['bg_id'];
}
background_select();
Function:
function background_select() {
global $bg_id;
global $bg_type;
if($bg_id='999'){
unset($GLOBALS['bg_id']);
$query = "SELECT id FROM background WHERE active='yes' AND type='$bg_type' ORDER BY rand() LIMIT 1";
$result = mysql_query($query) or die('MySQL error: ' . mysql_error() . '<hr/>' . $query);
while ($row = mysql_fetch_assoc ($result)) {
$bg_id = $row['id'];
}
}
}
Currently, while testing with nothing being passed in the URL, it's returning bg_id's value as 999, which is right going into the function, but why is the function not setting the new value?
I tried using unset at the beginning of the function, but although it did destroy the value, it still didn't get populated with a new value:
unset($GLOBALS['bg_id']);
I echo'd the query, and everything seems to be correct there:
SELECT id FROM background WHERE active='yes' AND type='3' ORDER BY rand() LIMIT 1
And I echo'd $row['id'] in the while loop. It returned the correct result.
So I think it's got to be the way I'm handling the variable.
Any help would be appreciated,
json