Forum Moderators: coopster

Message Too Old, No Replies

select query in function not returning content?

good connection; no errors; output but no content

         

DebW

9:57 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



My connection works, my script runs without errors, warnings, etc, but the content that should be found from this function isn't coming through to the output?

This function sits at the end of the page, right after the connection function:

function getStopGIS()
{
$query = "SELECT * FROM GIS WHERE State='$State' AND Stop='$Stop'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
return mysql_fetch_array($result,MYSQL_ASSOC);
}

And the script is above, just after the connection function call:

getStopGIS();
$getStopGIS = getStopGIS();

$County = $getStopGIS['County'];
$Elevation = $getStopGIS['Elevation'];
$Long_degree = $getStopGIS['Long_degree'];
$Long_minutes = $getStopGIS['Long_minutes'];
$Lat_degree = $getStopGIS['Lat_degree'];
$Lat_minutes = $getStopGIS['Lat_minutes'];

echo "<h2>Welcome to $Stop, $State of $County County!</h2>\n
<table border=\"0\">\n
<tr><td>Elevation:</td><td>$Elevation feet</td></tr>\n
<tr><td>Longitude:</td><td>$Long_degree degrees, $Long_minutes minutes</td></tr>\n
<tr><td>Latitude:</td><td>$Lat_degree degrees, $Lat_minutes minutes</td></tr>\n
</table>\n

</body>\n
</html>\n";

Psychopsia

10:45 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



Hi DebW!

You should use global [us2.php.net] so you can use those vars inside the function.

function getStopGIS()
{
global $State, $Stop;

...
}

[edited by: Psychopsia at 10:45 pm (utc) on Sep. 20, 2006]

DebW

5:42 pm on Sep 21, 2006 (gmt 0)

10+ Year Member



Psychopsia;

You are a GODSEND -- thank you, thank you, thank you.

I had the global placed in the main program, before the function call, not understanding that it had to be INSIDE the function. I just moved it, per your solution, and it is now displaying the expected content.

I am SO VERY GRATEFUL.

Psychopsia

5:51 pm on Sep 21, 2006 (gmt 0)

10+ Year Member



Great, I'm happy to hear that!