clankill3r
-
Posts
106 -
Joined
-
Last visited
Posts posted by clankill3r
-
-
i have a array calles $articles, this is a part of it:
Array ( [1335905082] => Array ( [channel] => [title] => SimpleXMLElement Object ( [0] => NEW PRODUCT – Blue 7-segment clock display – 0.56 digit height ) [link] => SimpleXMLElement Object ( [0] => http://www.adafruit.com/blog/2012/05/01/new-product-blue-7-segment-clock-display-0-56-digit-height/ ) [comments] => SimpleXMLElement Object ( [0] => http://www.adafruit.com/blog/2012/05/01/new-product-blue-7-segment-clock-display-0-56-digit-height/#comments ) [pubDate] => SimpleXMLElement Object ( [0] => Tue, 01 May 2012 20:44:42 +0000 ) [timestamp] => 1335905082 [description] => NEW PRODUCT – Blue 7-segment clock display – 0.56 digit height. Design a clock, timer or counter into your next project using our pretty 4-digit seven-segment display. These bright crisp displays are good for adding numeric output. Besides the four 7-segments, there are decimal points on each digit and an extra wire for colon-dots in [...] [isPermaLink] => SimpleXMLElement Object ( [0] => false ) [creator] => adafruit
when i use:
foreach($articles as $article) { $title = $article['title'][0]; echo '<pre>'; print_r($title); echo '</pre>'; }
i get stuff like:
SimpleXMLElement Object(
[0] => NEW PRODUCT – Yellow 7-segment clock display – 0.56 digit height
)
SimpleXMLElement Object
(
[0] => NEW PRODUCT – Dual H-Bridge Motor Driver for DC or Steppers – 600mA – L293D
)
But i expected:
NEW PRODUCT – Yellow 7-segment clock display – 0.56 digit heightNEW PRODUCT – Dual H-Bridge Motor Driver for DC or Steppers – 600mA – L293D
what do i do wrong?
-
I try to get the content from
http://www.adafruit.com/blog/feed/
some stuff is like this:
<![CDATA[Super simple drawdio + glove @ Studio Contrechoc. we experimented with a simplified drawdio, then we combined this bit of electronics with a first glove the cyclist glove. To make this terribly designed monster more fashionable, by-wire.net made another fine glove. We had to find the right kind of small speaker, and we used a [...]
]]>
no idea if that matters.
Atm i have this:
$xml = getFileContents("http://www.adafruit.com/blog/feed/"); $xmlTree = new SimpleXMLElement($xml); //foreach() //print_r2($xmlTree); for($i = count($xmlTree->channel->item)-1; $i >= 0; $i--) { $item = $xmlTree->channel->item[$i]; print_r2($item); //print_r2($item->category); //$category = $item->category; //print_r2($category); }
it prints stuff like:
SimpleXMLElement Object
(
[title] => New videos – Customer service, shipping, order status and more…
[link] => http://www.adafruit.com/blog/2012/04/27/new-videos-customer-service-shipping-order-status-and-more/
[comments] => http://www.adafruit.com/blog/2012/04/27/new-videos-customer-service-shipping-order-status-and-more/#comments
[pubDate] => Fri, 27 Apr 2012 17:00:00 +0000
[category] => SimpleXMLElement Object
(
)
[guid] => http://www.adafruit.com/blog/?p=30479
[description] => SimpleXMLElement Object
(
)
)
category and description are empty, how can i get that content?
print_r2 is just this:
function print_r2($val){ echo "<pre>"; print_r($val); echo "</pre>"; }
-
dankjewel / thanks
-
I have a table with words, what is a correct query to trim all words?
this is wrong:
$query = "UPDATE negative_words TRIM word";
it's structured like
id - word - rating
and negative_words is the tabel name.
-
thank god it was that simple.
thanks
-
I have a database with articles, i also have a database with ratings.
The ratings.articleId is for articles.id, in example if ratings.articleId = 50 then it belongs to the one where articles.id = 50;
$t is a number
$query = "SELECT articles.id, articles.headline ratings.rating FROM articles "; $query .= "LEFT JOIN ratings ON (ratings.articleId=articles.id) "; $query .= "WHERE articles.id>'$t'";
this is the error atm:
Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.rating FROM articles LEFT JOIN ratings ON (ratings.articleId=articles.id) WHERE' at line 1 -
i mean print_r
thanks, it works like a champ now!
-
atm i have this in a function:
$returnInfo = array(); $returnInfo["totalWords"] = $totalWords; $returnInfo["uniqueWords"] = count($uniqueWords); $returnInfo["positiveWords"] = $positiveWords; $returnInfo["negativeWords"] = $negativeWords; $returnInfo["rating"] = $mappedrating; return $returnInfo;
If i recursive print it it says Array instand of my expected values.
p.s., i have found examples where the array get's created in 1 line with all there values but i prefer not to do that since it will be a very long line.
-
-
thanks, the insert works now.
One more thing, i have a function to check if something is inserted:
function timeStampExists($pubDate) { //$query = "SELECT * FROM articles WHERE timestamp='$timestamp'"; $query = "SELECT * FROM articles WHERE timestamp='STR_TO_DATE('$pubDate', '%a, %d %b %Y %T')'"; $res = mysql_query($query); if (mysql_num_rows($res) > 0) { return true; } else { return false; } }
I only get this error:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /
on this line:
if (mysql_num_rows($res) > 0) {
-
How do i get a MySQL timestamp out of 'Thu, 01 Dec 2011 20:22:52 +0100' ?
-
$query = "INSERT INTO articles VALUES ('', '$headline', '$description', '$broadtext', '$timestamp', '$categoryID')";
where $timestamp = 1322767372 for example.
-
$pubDate:
Thu, 01 Dec 2011 20:22:52 +0100
$timestamp = strtotime($pubDate);
gives:
1322767372
so that seems to be ok.
Also i get no query errors for inserting, only all values it inserts are 0000-00-00 00:00:00
I tried different setting in my database, this was the last:
# Kolom Type Collatie Attributen Null Standaardwaarde Extra
5 timestamp timestamp on update CURRENT_TIMESTAMP Nee CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
-
It used to set it by 11 if i didn't fill in anything.
Anyway, i did set it for the id now, same thing as above... a red error box without a error
-
sometimes a image explains more then 1000 words:
i don't get it.
-
found it, i have to do it like this:
if (isset($item->enclosure)){
if (isset($item->enclosure->attributes()->url)){
$imageUrl = (string)($item->enclosure->attributes()->url);
}
}
-
I asume that in my case it would be
if (isset($item->enclosure->attributes()->url)) {
but this produces still the warning
-
thanks mate!
How can i check if the atribute exists? In some cases it's not there and then i get:
Warning: main() [function.main]: Node no longer exists in / -
yes no errors the, but neither a url.
-
I want to get the url in the [@attributes]
Atm i get the title like this
foreach ($xmlTree->channel->item as $item) { echo '<p>'.$item->title.'</p>'; }
i tried this
$imageUrl = $item->enclosure->@attributes->url; print_r2($imageUrl);
but then i get this error:
Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in /this is the XML:
[0] => SimpleXMLElement Object(
[title] => #3315: Woord van het jaar: weigerambtenaar, Arabische lente tweede, plaszak derde
[pubDate] => Sat, 26 Nov 2011 17:00:55 +0100
[guid] => nieuws_153690
[description] => SimpleXMLElement Object
(
)
[enclosure] => SimpleXMLElement Object
(
[@attributes] => Array
(
=> http://www.nrc.nl/wp-content/uploads/2011/11/vmBruidstaart5501_63103-586x4801-300x245.jpg
-
thanks but that's not what i meant, i should have been more clear.
I want to show multiple images in columns:
[ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ]
And therefore a image like this [ ] should be a rectangle so that's why i want to center them since often there is the more important content of a image.
-
How can i get a image in a rectangle without scretching the image?
I just want to center the image and have it set as background but i don't know what element to use for that.
-
2 times thanks
-
First i will show the code that activates the error:
if($current_host != null) { print_r2("1"); print_r2($current_host); print_r2($current_foundResult); print_r2("2"); $current_host::addFoundResult($current_foundResult); }
this is the output:
1
Host Object
(
[hostname] => www.google.nl
[foundResults] => Array
(
)
)
FoundResult Object
(
Fatal error: Using $this when not in object context in ~~~~~~~~~~~~~ on line 385
the error comes from this line:
$this->foundResults[] = $foundResult;
class Host { public $hostname; public $foundResults; public function __construct($hostname) { $this->hostname = $hostname; $this->foundResults = array(); } public function addFoundResult($foundResult) { $this->foundResults[] = $foundResult; } }
what i don't get about it is that both the Host Object and the FoundResult Object exist...
get content of array
in PHP Coding Help
Posted
yeah ok with echo it goes correct but i still wonder why it goes like that?
althought this fixes it (bad fix i suppose?)
$title = "".$article['title'][0];