I Tried retrieving my data from $result via:
$result->pluck('request_time');
and
$result->request_time;
Both give me a non-object error,
var_dump returns:
array (size=1)
0 =>
object(stdClass)[167]
public 'id' => string 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (length=38)
public 'request_time' => string '2015-05-10 17:01:02' (length=19)
public 'account_id' => int XXXXXXX
public 'NOW()' => string '2015-05-14 02:03:12' (length=19)
How do I retrieve the data without using the DB::table->pluck method?
It's giving you a non-object error because $result is an array.
Try $result[0]->request_time;
Try
$result = DB::table('yourtable')->where('foo', 'bar')->first();
dd($result->request_time);
Related
i am trying to get some values out of an Std Object in Laravel.
I can get anything out, with no problem, but not the last one
my object looks like this (var_dump())
object(stdClass)[208]
public 'id' => int 2
public 'vorname' => string 'Thomas' (length=5)
public 'nachname' => string 'Kemmet' (length=5)
public 'geburtstag' => string '1988-05-05' (length=10)
public 'verein_id' => int 1
public 'verein_name' => string 'Kolandorf' (length=20)
public 'game' => string '2016-10-28' (length=10)
when i do
echo $spieler->id;
i get the id. But when i try
echo $spieler->game;
i get an error with Undefined property: stdClass::$game
why is it like this? and how to get the last value...
Make sure that the game field is a string in the database you retrieve it from.
Try changing the order of the fields in order to see if its always the last one which has the problem.
I'm having problems with including / using external libraries in CodeIgniter 3.0. So this is what i did so far:
I have placed simple_html_dom.php file in my application/libraries folder
Then i'm auto loading it with this line of code in
/*
example of CI
$autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array('simple_html_dom' => 'shd');
And this is my controller
public function index()
{
$html = $this->shd->str_get_html('<html><body>Hello!</body></html>');
var_dump($html);
die();
$this->load->view('parser');
}
Which provides me an error of:
A PHP Error was encountered
Severity: Error
Message: Call to undefined method simple_html_dom::str_get_html()
Filename: controllers/Parser.php
Line Number: 8
Documentation of simple_html_dom can be found on this link
To me it looks like librarie gets loaded, but i can't use its functions.
I hope somebody can help. Thank you in advance!
I found a solution. After checking documentation of simple html dom, i found out that you can also use object oriented way. So my controller looks like this now:
$html = new simple_html_dom();
$html->load('<html><body>Hello!</body></html>');
var_dump($html);
And i have result:
object(simple_html_dom)[17]
public 'root' =>
object(simple_html_dom_node)[18]
public 'nodetype' => int 5
public 'tag' => string 'root' (length=4)
public 'attr' =>
array (size=0)
empty
public 'children' =>
array (size=1)
0 =>
object(simple_html_dom_node)[19]
...
public 'nodes' =>
array (size=1)
0 =>
object(simple_html_dom_node)[19]
...
public 'parent' => null
public '_' =>
array (size=2)
0 => int -1
1 => int 4
public 'tag_start' => int 0
private 'dom' =>
&object(simple_html_dom)[17]
public 'nodes' =>
array (size=4)
0 =>
object(simple_html_dom_node)[18]
public 'nodetype' => int 5
public 'tag' => string 'root' (length=4)
public 'attr' =>
array (size=0)
...
public 'children' =>
array (size=1)
...
public 'nodes' =>
array (size=1)
...
public 'parent' => null
public '_' =>
array (size=2)
...
public 'tag_start' => int 0
private 'dom' =>
&object(simple_html_dom)[17]
you can use
$this->load->library("simple_html_dom"); //class name should come here
And make sure simple_html_dom.php class name is simple_html_dom
Try this -
$autoload['libraries'] = array('simple_html_dom');
You can do this like that:
$this->load->library("simple_html_dom");
$this->simple_html_dom->your_method();
I need to check xml feeder updated date and updated date from my database and get just updated date that are not exists in my database.
I am doing that because i need to get just odds changes from last time that parser start.
But there is problem it's stuck and nothing happened, just loading page, all day.
Here is code:
$updDate = $this->PDO->prepare("select distinct FixtureMatch_Id,UpdatedDate from odds");
$updDate->execute();
$updDate->setFetchMode(PDO::FETCH_ASSOC);
while($row = $updDate->fetch()){
$odds=$this->soccer->GetAllOddsByFixtureMatchId(
array("fixtureMatch_Id"=>$row['FixtureMatch_Id']))
->xpath("//Odds[not(contains(UpdatedDate,$row['UpdatedDate']))]");
echo $row['FixtureMatch_Id'] . ' : ' . $row['UpdatedDate'] . '<br>';
}
}
this is how it looks when i var dump without xpath like this:
$odds=$this->soccer->GetAllOddsByFixtureMatchId(
array("fixtureMatch_Id"=>$row['FixtureMatch_Id']))->OddsList->Odds;
xml
object(SimpleXMLElement)[11]
public 'FixtureMatch_Id' => string '325006' (length=6)
public 'Bookmaker' => string 'Pinnacle' (length=8)
public 'UpdatedDate' => string '2015-05-23T14:58:51.213' (length=23)
public 'Type' => string 'Over/Under 2.5' (length=14)
public 'HomeOdds' => string '1.85' (length=4)
public 'AwayOdds' => string '2.08' (length=4)
Update: In database is abount 16000 rows in odds table, is it problem?
I'm creating e-commerce shop with Amazon API integration.
The problem I faced with is I cannot get items from specific node.
So I've tried many ways to do that, last one was something like this:
$fields = array();
$fields['AssociateTag'] = "ItemSearch";
$fields['Condition'] = 'All';
$fields['Operation'] = 'ItemSearch';
$fields['Version'] = '2013-08-01';
$fields['BrowseNode'] = $catId;
$fields['ResponseGroup'] = "Images,ItemAttributes,Offers";
$fields['Service'] = 'AWSECommerceService';
$fields['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
$fields['AWSAccessKeyId'] = $this->accessKey;
After that call I have the output:
public 'Items' =>
object(SimpleXMLElement)[150]
public 'Request' =>
object(SimpleXMLElement)[139]
public 'IsValid' => string 'True' (length=4)
public 'ItemSearchRequest' =>
object(SimpleXMLElement)[138]
public 'BrowseNode' => string '1289481011' (length=10)
public 'Condition' => string 'All' (length=3)
public 'ResponseGroup' =>
array (size=3)
0 => string 'Images' (length=6)
1 => string 'ItemAttributes' (length=14)
2 => string 'Offers' (length=6)
So I can see my request, but no items were returned to me.
By the way, ItemLookup, ItemSearch with keywords and BrowseNode operations work just fine.
What can I do to get items from node with spicific ID without using keywords?
I figured out what happened. I didn't set SearchIndex when I point BrowseNode ID.
So there was no result.
I have the need to display the bucket contents on my S3 and I am using Amazon's PHP SDK.
My code is simply
$objects = $s3->list_objects("mybucket",array("max-keys"=>5));
var_dump($objects);
The response I get from the server is very complicated for me to understand -
It's essence is
Object(CFResponse)[107]
public 'header' =>
array (size=11)
'x-amz-id-2' => string
...
public 'body' =>
object(CFSimpleXML)[106]
public '#attributes' =>
array (size=1)
'ns' => string 'http://s3.amazonaws.com/doc/2006-03-01/' (length=39)
public 'Name' => string 'cdneu.2yourfacecdn.com' (length=22)
public 'Prefix' =>
object(CFSimpleXML)[3]
public 'Marker' =>
object(CFSimpleXML)[105]
public 'MaxKeys' => string '5' (length=1)
public 'IsTruncated' => string 'true' (length=4)
public 'Contents' =>
array (size=5)
0 =>
object(CFSimpleXML)[104]
...
1 =>
object(CFSimpleXML)[103]
...
2 =>
object(CFSimpleXML)[102]
...
3 =>
object(CFSimpleXML)[101]
...
4 =>
object(CFSimpleXML)[100]
...
public 'status' => int 200
I believe the part under the 'Contents' is what I'm looking for but how do I access it ? I'm used to receiving arrays where I can figure out what the keys are and how to access but this here is difficult for me ,
Any guesses?
try this in order to list the key element of each object:
$s3 = new AmazonS3();
$objects = $s3->list_objects("YOUR BUCKET NAME",array("max-keys"=>5));
foreach ($objects->body->Contents as $item){
print_r($item->Key."");
}
You can access contents as follows
$contents = $objects['Contents'];