Jump to content


Photo

Command Line php script


  • Please log in to reply
2 replies to this topic

#1 cr-ispinternet

cr-ispinternet
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 29 October 2006 - 01:23 PM

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

#2 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 29 October 2006 - 03:09 PM

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...


<?

	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);

?>

Hope that's of some use.  :)

#3 cr-ispinternet

cr-ispinternet
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 29 October 2006 - 05:00 PM

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.bluc...maps/index.html

thats what ive been trying to do :-)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users