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.

get search query not working

Discussion in 'PHP' started by Luke Jones, Jul 17, 2007.

  1. #1
    Hello,
    For some reason, in one of my php scripts my get search query command is not working.
    Here it is:
    $searchquery = ($_GET['query']);
    // connect to a URL
    if (!$wsql->connect('url', '$searchquery')){
    print 'Error while connecting: ' . $wsql->error;
    exit;
    The search query is taken from the url on passed on from the previous page.
    (The search query in this case is an url. I'm using ?query= to pass through an url.)
    The script is reading it as $searchquery instead of the url.
    Could you please tell me what could possibily be stopping this from working?
    Thanks
     
    Luke Jones, Jul 17, 2007 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put var_dump($searchquery) to check the value of the variable.

    What does it print out?
     
    MMJ, Jul 17, 2007 IP
  3. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your problem is that you don't need the single quotes around $searchquery...

    wsql->connect('url', $searchquery)

    will work fine
     
    ecentricNick, Jul 17, 2007 IP
  4. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you very much for you help!
    EccentricNick, your advice was right, it's working now.
    I hope to be able to return the help one day.
     
    Luke Jones, Jul 17, 2007 IP
  5. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ah, just some "rep" will do!
     
    ecentricNick, Jul 17, 2007 IP
    Luke Jones likes this.
  6. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have another question, which I think you'll be able to answer.
    How do I take information out of specific points in an url?
    For example, in this url, which will be in the browser:
    
    http://news.search.yahoo.com/news/rss%3fei%3dUTF-8%26p%3dlarge%2bcrocodiles%26eo%3dUTF-8&TEMPLATE=newsitemtemplate.html&GUID=http://us.rd.yahoo.com/dailynews/rss/search/large%2bcrocodiles/SIG%3d11qv3b00d/*http%253A//news.yahoo.com/s/kmbc/20070717/lo_kmbc/13693092
    Code (markup):
    I want to take the part that follows the *, and display it in a link on the new page.
     
    Luke Jones, Jul 17, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    
    $url = 'http://news.search.yahoo.com/news/rss%3fei%3dUTF-8%26p%3dlarge%2bcrocodiles%26eo%3dUTF-8&TEMPLATE=newsitemtemplate.html&GUID=http://us.rd.yahoo.com/dailynews/rss/search/large%2bcrocodiles/SIG%3d11qv3b00d/*http%253A//news.yahoo.com/s/kmbc/20070717/lo_kmbc/13693092';
    
    $new_url = rawurldecode(rawurldecode(end(explode('*', $url))));
    
    echo $new_url;
    
    PHP:
    Seems like the URL has been URL encoded twice. That's why I'm applying the function twice to decode it.
     
    nico_swd, Jul 17, 2007 IP
  8. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks a lot Nico.
    Could I replace * with a different to extract from a different starting point in the url?
    Was it necessary to decode the url, seeing that the part I wanted was not encoded?

    Thanks
     
    Luke Jones, Jul 17, 2007 IP
  9. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    For example:
    
    http://news.google.com/news/url?sa=T&ct=us/4-0&fd=R&url=http://www.theregister.co.uk/2007/07/17/google_itvcon_keynote/&cid=0&ei=jUGdRtXqO4T20AHt3KiJAQ
    Code (markup):
    Do I replace * with url= ?
     
    Luke Jones, Jul 17, 2007 IP
  10. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hello,
    I have now written the following code:

    
    $url = ($_GET['url']);
    $new_url = rawurldecode(rawurldecode(end(explode('*', $url))));
    
        // connect to a URL 
        if (!$wsql->connect('url', $new_url)){
            $url = ($_GET['query']);
            $new_url = rawurldecode(rawurldecode(end(explode('*', $url))));
            }
                if (!$wsql->connect('url', $new_url)){
            print 'Error while connecting: ' . $wsql->error; 
            exit; 
        } 
    
    PHP:
    I'm hoping that if the script cannot extract the url from the complete url, then it will try to extract it from the query.
    Unfortunately, if it cannot extract it from the url, it stops. It doesn't try to get it from the query.
    What am I doing wrong?
    (In case it seems strange that I'm doing this: $url = ($_GET['url']); works for Google feeds, but doesn't for Yahoo feeds; $url = ($_GET['query']); works for Yahoo, but not Google. So, I need the script to try both before stopping.)

    Please help me with this.

    Thanks.

    Luke
     
    Luke Jones, Jul 19, 2007 IP