Jump to content

Command Line php script


cr-ispinternet

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
Link to comment
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.  :)
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.