views:

60

answers:

2

I would like to write a PHP function that calls another function

Page 1. User selects item from drop down.

(I then post to the same page.)

Page 1. (I have a query on the page that's based off of which item is selected) (In this case I'm returning the lat and long of the item.)

$latitude = $row_farms['lat']; $longitude = $row_farms['long'];

THEN

(on the same page - I'm trying to run another query on another table using the previous queried data)

I hope this makes sense.

thanks.

+1  A: 

So, you want to pass parameters between "pages" which all are the same PHP page?

Well, the global $_REQUEST array is your friend, unless I'm not understanding your problem (which isn't shaped as a question, BTW). Your URL would be example.php?lat=xxx&long=yyy, and you pull out those in your script with $_REQUEST['lat'] and $_REQUEST['long'], and if you want a "pager" as well, you can do the same as in $_REQUEST['page'].

But I'm having a hard time understanding what you actually struggle with, so if you could add or edit info, hopefully with some code, that's be great.

AlexanderJohannesen
+1  A: 

Assuming you have your database connection declared globally (outside your functions), you can do something like this:

function get_data()
{
   global $con;

   // Run first query, get data

   second_function($latitude, $longitude);
}

function second_function($latitude, $longitude)
{
   global $con;

   $result = mysql_query("SELECT * FROM other_table WHERE `lat`={$latitude} AND `long`={$longitude}");

   // Process result
}
Steven Richards