[solved] my first function, be gentle on me ;)
Posted: Tue Aug 23, 2005 7:27 am
Hi all, here it is, my first attempt at a function.
Could anyone tell me why this won't work?
if I call this with, nothing happens (that I can see when echoing $town in a script):
(noting that $city_closest is an integer that matches an ID in the table)
I have connected to the database already in the script before I call the function and I've included the function in my script (as it's in a seperate file).
Stumped
Rob
UPDATE!!
I've tried this also, but no luck
Could anyone tell me why this won't work?
Code: Select all
//Find the actual name of a town based on its ID from the database
function findtown( $city_closest )
{
mysql_select_db($dbname);
$sql = "SELECT * FROM towns WHERE town = $city_closest";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
return $town_id = $Xcontent["id"];
return $town_name = $Xcontent["town"];
return $town_state = $Xcontent["state"];
return $town_popularity = $Xcontent["popularity"];
}Code: Select all
$town = findtown($city_closest);I have connected to the database already in the script before I call the function and I've included the function in my script (as it's in a seperate file).
Stumped
Rob
UPDATE!!
I've tried this also, but no luck
Code: Select all
function findtown( $city_closest )
{
mysql_select_db($dbname);
$sql = "SELECT * FROM towns WHERE town = $city_closest";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
return ($town_id = $Xcontent["id"]);
return ($town_name = $Xcontent["town"]);
return ($town_state = $Xcontent["state"]);
return ($town_popularity = $Xcontent["popularity"]);
}