Jump to content

clankill3r

Members
  • Posts

    106
  • Joined

  • Last visited

Posts posted by clankill3r

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

    NEW PRODUCT – Dual H-Bridge Motor Driver for DC or Steppers – 600mA – L293D

     

    what do i do wrong?

  2. 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>";
    }
    

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

  5. 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) {

     

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

     

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

                                [link] => http://www.nrc.nl/nieuws/2011/11/26/woord-van-het-jaar-weigerambtenaar/?utm_campaign=rss&utm_source=syndication

                                [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

                                                [length] =>

                                                [type] => image/jpeg

                                            )

     

                                    )

     

                            )

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

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

    (

        =>

        [title] =>

        [visits] =>

    )

     

    2

     

     

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

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