Jump to content

Archived

This topic is now archived and is closed to further replies.

cr-ispinternet

Command Line php script

Recommended Posts

Hi guys,

im doing some last minute work on a comapny portal
by adding gogle maps in there, the engineer can then look
up his jobs for the day and also view a map of the location
where the job is at ( accurate to 100M )

problem is im having a nightmare with some code in order
to get the geo locations so i can feen them to the google maps page.

i have a database called pda_jobs in here is all the info i need for the job
from there i need to copy 5 or 6 fields over to another table called locations
this table basically if for a view of the uk with all jobs active for the day
and where they are mapped by the google api ballon.

what im struggling with is when ever i execute the script ive written
it does just one line and thats it, i think personally im being stupid
and have missed something.

heres the code

the pda_jobs database has a field called converted so each time the
script is run it does not have to process each one again.

#!/usr/bin/php -q

<?

        mysql_connect("localhost","databse","password");
        $query = "SELECT * from pda_jobs where converted= 'no'";
        $result = mysql_db_query('blucat',$query);
        while($row = mysql_fetch_object($result)) {

        $display_company_name = "$row->company_name";
        $display_postcode_district = "$row->postcode_district";
        $display_postcode_sector = "$row->postcode_sector";
        $display_job_number = "$row->job_number";
        $display_job_date = "$row->job_date";

        }

                /* Generates Insert Statement */
                $query1 = "insert into locations values(
                '',
                '',
                '',
                '',
                '$display_company_name',
                '$display_postcode_district',
                '$display_postcode_sector',
                '$display_job_number',
                '$display_job_date',
                'no')";
                $result1 = mysql_db_query('blucat',$query1);

                $query3 = "UPDATE pda_jobs set converted='yes'";
                $result3 = mysql_db_query('blucat',$query3);

?>

can any one tell me how i can re write the code so it processes all
entries as its reading one line then stopping.

say there are 4 entries for jobs today, when the script is ran from cron
i want it to process each of those 4 lines and insert the data into
the locations databse.

any help would be much appreciated

Alan

Share this post


Link to post
Share on other sites
I think your problem lies in the position of the closing brace of the while loop.  It should be lower - if I understand you correctly - like this...

[code]

<?

mysql_connect("localhost","databse","password");
$query = "SELECT * from pda_jobs where converted= 'no'";
$result = mysql_db_query('blucat',$query);

while($row = mysql_fetch_object($result))
{
$display_company_name = "$row->company_name";
$display_postcode_district = "$row->postcode_district";
$display_postcode_sector = "$row->postcode_sector";
$display_job_number = "$row->job_number";
$display_job_date = "$row->job_date";

/* Generates Insert Statement */
$query1 = "insert into locations values(
'',
'',
'',
'',
'$display_company_name',
'$display_postcode_district',
'$display_postcode_sector',
'$display_job_number',
'$display_job_date',
'no')";
$result1 = mysql_db_query('blucat',$query1);
}

$query3 = "UPDATE pda_jobs set converted='yes'";
$result3 = mysql_db_query('blucat',$query3);

?>
[/code]

Hope that's of some use.  :)

Share this post


Link to post
Share on other sites
ha ah ha

makes me laugh you know php, you get high blood preasure
sweats, and anger all from....

wait for it...

a }

bloody things

well thats me sorted

http://engineer.blucat.co.uk/gmaps/index.html

thats what ive been trying to do :-)

Share this post


Link to post
Share on other sites

×

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.