Forum Moderators: coopster

Message Too Old, No Replies

RSS reader with search query

         

chadon

6:10 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Hi all,
I am a noob in the php world and I would like to offer a search engine powered by the RSS feed of my classifieds site to other webmasters.

I have an RSS reader script ready to work and here is what I would like to do. The script needs an RSS feed URL to display the items in an html page:

I managed to have the search query written in the web page with the get function from the search form:

$query = $_GET["query"];

For the script, I need to enter the query inside the RSS feed URL

$RSSfeedurl = "http://mydomain.com/rss.php?query=KEYWORD";

By entering a keyword manually in the URL the script shows the realted ads with no problem but if I enter the following URL:
$RSSfeedurl = "http://mydomain.com/rss.php?query=$query";
the query is not read.

Does anyone know the correct way to do this? I am not English and don't know much about php so I hope you understand what I mean. :)

jatar_k

7:52 pm on Dec 2, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld chadon,

I will repeat to be sure I understood

if you edit this url
$RSSfeedurl = "http://mydomain.com/rss.php?query=KEYWORD";
manually then that line works but if you add the variable it doesn't?

seems odd, makes me think of two things, first is to concatenate your var properly and not rely on "

$RSSfeedurl = "http://mydomain.com/rss.php?query=" . $query;

not that we will see a difference now but, hey, you never know.

the other thing would be to spit out what's in $query to make sure it is correct, or even echo the whole url, maybe this

echo '<p>query: ',$query;
$RSSfeedurl = "http://mydomain.com/rss.php?query=" . $query;
echo '<p>RSSfeedurl: ',$RSSfeedurl;

then you can have a look

chadon

8:16 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



I gave up on my script since my post and thanks to your reply, I found the solution at first try. It was stupid and the right code was the following:
$RSSfeedurl = "http://mydomain.com/rss.php?query=$query;";

instead of:
$RSSfeedurl = "http://mydomain.com/rss.php?query=$query";

Thank you very much Jatar_k for your help :)

jatar_k

8:28 pm on Dec 2, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



no stupid mistakes, it was just in BETA ;)

nice catch

chadon

8:37 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



Sorry to bother you again but my joy didn't last very long. Now I have a problem when the search is made with a space. Is there a way to have a query like "keyword1 keyword2" replaced by "keyword1+keyword2"?

chadon

11:11 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



Never mind. Google gave me the information I needed. I had to add the following line in the file:
$keywords = ereg_replace(' ', '+', $query );

then use:
$RSSfeedurl = "http://mydomain.com/rss.php?query=$keywords"; 

Now my first script is out of beta and I am very happy :)

Thank you again for your help ;)