1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with if statement please...

Discussion in 'PHP' started by Devilfish, Feb 28, 2009.

  1. #1
    Hi folks,

    I'm looking for help with an if statement and showing a logo.

    I have a pagerank checker and I want to show a gif of a PR button along with the PR result. But not sure how to code it...

    This is part of the code that returns the PR:

    //get google pagerank
    
    function getpagerank($url) {
    
        $query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
    
        $data=file_get_contents_curl($query);
    
        //print_r($data);
    
        $pos = strpos($data, "Rank_");
    
        if($pos === false){} else{
    
            $pagerank = substr($data, $pos + 9);
    
            return $pagerank;
    
        }
    
    }
    PHP:
    And this is the code that shows the PR:

    <?php
    
    $url=$_REQUEST['url'];
    
    echo "Google Pagerank = PR".getpagerank($url)."<br />";
    
    ?>
    PHP:
    So if the result is PR4 then I also want to show a gif of [​IMG] and the picture changes with every PR results. Does that make sense? And also offer code so that people can put that icon on their website.

    Any help is apprecaited!

    Thank you! :)
     
    Devilfish, Feb 28, 2009 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    If ($pagerank==4) { echo "<img scr './pr_icons/pr4.gif '>"; }

    If ($pagerank==5) { echo "<img scr './pr_icons/pr5.gif '>"; }

    Repeat process for as many as you like.

    You need to do the second part as a text area that they can copy and link to the image on your site.
     
    Colbyt, Feb 28, 2009 IP
    Devilfish likes this.
  3. tack

    tack Peon

    Messages:
    171
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    colbyt is right. i was also worked such a script and there I was used 10 jgp for showing page rank.
     
    tack, Feb 28, 2009 IP
  4. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #4
    Than you very much Colbyt, I'll try that right now! :)
     
    Devilfish, Feb 28, 2009 IP
  5. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #5
    The $pagerank variable is in another file but the file is called at the top of the script page.

    Let me explain, I have a pr.php file to display the contents of the script and the pagerank_lib.php file that does all the fetching of data and calculating. This line is at the top of the pr.php file...

    require_once("pagerank_lib.php");
    Code (markup):
    So would the $pagerank variable work in the pr.php file? I can't get it to work using your above advice. I also changed it to this because it thought you had missed a few characters out...

    if ($pagerank==4) { echo "<img scr='/pr_icons/pr4.gif'>"; }
    Code (markup):
     
    Devilfish, Feb 28, 2009 IP
  6. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #6
    It's cool, I managed to figure it out!

    if ( getpagerank($url) == 4 ) { echo "<img src='/pr_icons/pr4.gif'>"; }
    Code (markup):
    Thanks for the starter! :)
     
    Devilfish, Feb 28, 2009 IP
  7. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Might be faster and easier using a switch.
     
    qualityfirst, Feb 28, 2009 IP
  8. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #8
    I've no idea what that means :p
     
    Devilfish, Feb 28, 2009 IP
  9. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #9
    The switch statement might be a tad faster but I don't think it will matter a lot. I can't write one of those on the fly.

    Yep I missed the = sign for sure.

    Glad you got it working.
     
    Colbyt, Feb 28, 2009 IP
  10. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #10
    Wow, forget the switch.

    Can't believe it took me so long to think of this.


    Just do
    
    $pagerank_no = getpagerank($url);
    ?>
    <img src="/pr_icons/pr<?php echo $pagerank_no ?>.gif">
    
    PHP:
    Should work.
     
    qualityfirst, Feb 28, 2009 IP
  11. young coder

    young coder Peon

    Messages:
    302
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #11
    just use
     $pagerank = getpagerank($url);
    echo "<img scr='/pr_icons/pr".$pagerank.".gif'>"; 
    PHP:
     
    young coder, Feb 28, 2009 IP
    Colbyt likes this.
  12. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #12
    That's what I said.

    Wasn't sure if $pagerank for the correct variable however.
     
    qualityfirst, Feb 28, 2009 IP
    Colbyt likes this.
  13. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #13
    But use that after:
    $pagerank_no = getpagerank($url);

    That makes it 2 lines of code and is a much better solution.
     
    Colbyt, Feb 28, 2009 IP
  14. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #14
    This is what I ended up using...

    echo "Google Pagerank = <img src='/pr_icons/pr".getpagerank($url).".gif'><br />";
    PHP:
    But I did use the if statements for another purpose so I did need to know how to do it! :)
     
    Devilfish, Feb 28, 2009 IP
  15. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #15
    Not to be a kill-joy, but what happens in the case of PR being N/A?
     
    qualityfirst, Feb 28, 2009 IP
  16. young coder

    young coder Peon

    Messages:
    302
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #16
     $pagerank = getpagerank($url);
    if ($pagerank == "N/A"){ echo "the page rank is unknown";  }
    else { echo "<img scr='/pr_icons/pr".$pagerank.".gif'>"; } 
    PHP:
     
    young coder, Mar 1, 2009 IP
  17. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #17
    Ah good thinking hehe.

    Unfortunately it doesn't like the "N/A".

    Is there a way I can say...if $pagerank does not equal a number? Or if $pagerank is not between 0 and 10, maybe in an array?

    Thanks for all your help! :)
     
    Devilfish, Mar 1, 2009 IP
  18. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #18
    
    if (ctype_digit(getpagerank($url))){
    echo "Google Pagerank = <img src='/pr_icons/pr".getpagerank($url).".gif'><br />";
    } else {
    echo "Google Pagerank = <img src='/pr_icons/prna.gif'><br />";
    }
    
    PHP:
     
    qualityfirst, Mar 1, 2009 IP
  19. Devilfish

    Devilfish Active Member

    Messages:
    396
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    70
    #19
    Thanks for your continued help qualityfirst but that didn't work.

    No matter what site I use, it always shows the 'else' option, i.e. no pr.
     
    Devilfish, Mar 1, 2009 IP
  20. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #20
    Try this

    
    $pagerank1 = getpagerank($url);
    if (ctype_digit($pagerank1){
    echo "Google Pagerank = <img src='/pr_icons/pr".$pagerank1.".gif'><br />";
    } else {
    echo "Google Pagerank = <img src='/pr_icons/prna.gif'><br />";
    }
    
    PHP:
     
    qualityfirst, Mar 1, 2009 IP