Jump to content

errors after server move


sublevel4

Recommended Posts

this code worked before a server move and now i get errors

 

<?php

require('includes/Basecamp.class.php');

$n=0;

$bc = new Basecamp('https://sub.basecamphq.com','name','password','simplexml');
$response = $bc->getProjects();

echo $response;

echo 'date created,Company name,Project name';

    // iterate the projects
    foreach($response['body']->project as $project){	  

	// output only where status is active
	if ($project[$n]->status == 'active'){		
		$created = $project[$n]->{'created-on'}.',';		
		$catagory = $project[$n]->company->name.',';
		$project = $project[$n]->name;
		//echo '<br>__________________________________<br>';
		$n++;
		$data_string .= $created . $catagory . $project."\n";
	}



}

echo $data_string;

$filename = 'active_jobs.txt';

file_put_contents($filename, $data_string); 

header('Content-disposition: attachment; filename='.$filename.'');
header('Content-type: text/plain');


?>

 

now i get

 

Warning: main() [function.main]: Cannot add element project number 1 when only 0 such elements exist in /home/...  .../basecamp/project_list_active.php on line 18

 

 

I am not sure what is going on here. Any help would be appreciated.

 

Thanks!

Link to comment
Share on other sites

Your code was probably producing that Warning before, but it was being hidden by the error_reporting/display_errors settings on the previous server.

 

However, your code, using the $n counter (what the Warning refers to) makes no sense. The foreach(){} loop is iterating over each of the $response['body']->project items. By referencing $project[$n]->status, where $n is incremented each pass through the foreach(){} loop, the first pass through the loop will reference $project[0]->status, the second pass through the loop (for the second $response['body']->project item) will reference $project[1]->status, then $project[2]->status, ...

 

The Warning indicates that there is no $project[1]->status in the data under the second $response['body']->project item and if there is no warning message for higher values, that would indicate that there is only two $response['body']->project items in the data and the foreach(){} loop only loops two times.

 

I suspect that your code appears to work because the first pass through the foreach(){} loop gets the correct data that you expect.

 

What does the actual data source look like and what result do you expect from it and what result are you getting now, ignoring the Warning message?

Link to comment
Share on other sites

if i put

 

<?php
require('includes/Basecamp.class.php');

$n=0;

$bc = new Basecamp('https://bsasgm.basecamphq.com','USERName','password','simplexml');
$response = $bc->getProjects();

    // iterate the projects
    foreach($response['body']->project as $project){	  

	echo $n. '<br/>';
	$n++;		


}





?>

 

I get a list of 0 through 2498

 

if i put in just

print_r($response['body']->project);

 

it returns

SimpleXMLElement Object
(
    [created-on] => 2009-11-30
    [id] => 4038672
    [last-changed-on] => 2009-12-21T21:02:37Z
    [name] => Reusable bags
    [status] => archived
    [company] => SimpleXMLElement Object
        (
            [id] => 1621970
            [name] => Marketing
        )

)

 

 

What i am trying to do is list each project as: Date created, ID, name, Status

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.