Jump to content

Selecting from a cursor


aleniko

Recommended Posts

Hi all;

I'm a Foxpro programmer and I'm trying to do some work with php. Here is my problem:

I need to create a few cursors and then select from the cursors.

In Foxpro its pretty simple -

select something from somewhere into cursor cur1

and then,

select * from cur1 where something = somethingelse

 

I'm having problems doing this with php. I tried declaring the cursor but I'm getting an error. Here is my entire declare code - all the math is for distance lookup.:

 

declare curdist1 CURSOR

FOR

  select acct,name,address2,krccust.city,krccust.state,krccust.zip,krccust.tel,zips.lat,zips.lon,

(

        3959 *

        acos(

                cos(radians($olat)) *

                cos(radians(zips.lat)) *

                cos(radians(zips.lon) - radians($olon)) +

                sin(radians($olat)) *

                sin(radians(zips.lat))

        )

) AS distance

                from krccust left join zips on krccust.zip=zips.zip  ;^M

 

$res = mysql_query("select * from curdist1 where distance > 10");

 

 

Link to comment
Share on other sites

I tried declaring the cursor but I'm getting an error.

Please post the error.

Please use code tags when posting code.

Please explain a bit more what exactly you are trying to do, as I certainly didn't understand (though someone else might understand it). From what I was able to gather, you may want to do something that is run on the client side, but if that is the case, you should know that PHP is serverside scripting.

Link to comment
Share on other sites

Error is:

Parse error: parse error, unexpected T_STRING, expecting '(' in /home/smartsco/public_html/krcweb/jj.php on line 34

Line 34 is

declare curdist1 CURSOR

 

I'm not sure what are code tags...

 

No, this is supposed to work server side only. I need to find records according to geographic proximity, but its a complicated criteria. So I want to create an initial cursor and do my queries on that.

 

Thanks and let me know if you need any additional info.

 

Link to comment
Share on other sites

Mysql does not have the cursor concept you describe but there are a couple of alternatives.

 

1)

    CREATE TEMPORARY TABLE curs1

    SELECT ... (your query) ...

 

    Then run your second query against this temp table.

 

2) Make your main query a table subquery

 

    select * from

      (

        SELECT .... (your main query) ...

      ) as curs1

    where distance > 10

   

 

Link to comment
Share on other sites

Thanks Barand;

So if I needed to run several queries on my initial query, what is the best way of doing so? Using option 2, I will need to run the initial query again and again for every secondary query I make, right?

 

Also, using option 1 would mean I need to create the temp table and populate it manually - not using a select command?

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.