sublevel4 Posted September 10, 2012 Share Posted September 10, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/ Share on other sites More sharing options...
lemmin Posted September 10, 2012 Share Posted September 10, 2012 Does the new server have outside network access? Try to ping sub.basecamphq.com on your server. Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/#findComment-1376830 Share on other sites More sharing options...
sublevel4 Posted September 11, 2012 Author Share Posted September 11, 2012 It does. I have a test script that is similar and it works fine. returns all the information. It seems to be breaking inside the foreach part but i can't tell what is not working. Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/#findComment-1376995 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2012 Share Posted September 11, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/#findComment-1376997 Share on other sites More sharing options...
sublevel4 Posted September 11, 2012 Author Share Posted September 11, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/#findComment-1377004 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2012 Share Posted September 11, 2012 All of the $project[$n] needs to be just $project Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/#findComment-1377007 Share on other sites More sharing options...
sublevel4 Posted September 11, 2012 Author Share Posted September 11, 2012 ah. ok. Now That works. Thank you for the help. I appreciate the time. Thank you, Dylan Quote Link to comment https://forums.phpfreaks.com/topic/268231-errors-after-server-move/#findComment-1377017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.