0

Hi All

I have created a simple php rss feed with works fine.

However what I would really like is for the rss feed to dynamically change based on a search form. i.e. User searches for all properties for Rent, of Apartment type only, clicks on the rss icon which is then a link to his custom made feed which then only sends him those properties based on his search input.

Any help would be really appreciated as I've looked quite extensively through Google and can't really find anything on combining a feed with a users' search...at the momemt my search form is on a different page and the results show on the same pages as the property search.

The code as I have it is:

<?php header('Content-Type: text/xml'); ?>
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
<channel>
<title>Dream Singapore Property - Newsfeed</title>
<link>
<p>http://www.xxxxxxxxxxxxxxxxxx.com</p>
<br />
<description>Properties for Sale & Rent in Singapore.</description>
<language>en-us</language>

<?php

// Connect to the database 
require_once ('myaccess/dbc.php');

// Retrieve the property data from MySQL
$query = "SELECT prop_id, prop_cat, add_area, prop_bedroom, prop_bathroom, prop_type, prop_saletype, prop_price, DATE_FORMAT(add_date_orig,'%a, %d %b %Y %T') AS add_date_orig_rfc, " .
"add_road, prop_desc FROM property_details ORDER BY prop_type DESC";
$data = mysqli_query($dbc, $query);

// Loop through the array of property data, formatting it as RSS
while ($row = mysqli_fetch_array($data)) { 
// Display each row as an RSS item
echo '<item>';
echo '  <title>' . 'Property ID:' . $row['prop_id'] . ' - ' .  $row['prop_cat'] . ' - ' . 'Property Type:' . ' ' . $row['prop_type'] . ' / ' .  $row['prop_saletype'] .'...</title>';
echo '  <link>http://www.xxxxxxxxxxxxxxxxxxxxxx.com/propertylisting_details.php?recordID=' . $row['prop_id'] . '</link>';
echo '  <pubDate>' . $row['add_date_orig_rfc'] . ' ' . date('T') . '</pubDate>';
echo '  <description><p class="maintextbold10">' . $row['prop_cat'] . ' - ' . $row['add_area'] . $row['prop_bedroom'] .   'Bedrooms' . ' ' .  $row['prop_bathroom'] . 'Bathrooms' . '</p></description><br />';
echo '  <description><p class="maintextbold10">' . $row['prop_desc'] . '</p></description>';
echo '</item>';
}
?>

</channel>
</rss>
4
Contributors
4
Replies
9
Views
5 Years
Discussion Span
Last Post by guruparthi
0

$beds = 2; //// input from search form
$area = 'london'; //// input from search form

$query = "SELECT * FROM property_details WHERE add_area='".$area."' AND  prop_bedroom => ".$beds." ORDER BY add_date_orig_rfc DESC";
// this should grab every property in London with two or more bedrooms and sort by date order descending

Try just googling for MySQL or SQL tutorial, the 'WHERE','LIKE','AND' & 'OR' commands are what you need to experiment with plus the wildcard control'%' so...

WHERE add_area LIKE '%London' 
//would pull out results for North London, South London etc
0

Hi Sogo7
Sorry for not geting back to you....

I understand the sql clauses etc....I should have been clearer.
What is happening is that the feed is not working with the WHERE clause in....

So I have the following:

<?php header('Content-Type: text/xml'); ?>
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
  <channel>
    <title>Dream Singapore Property - Property For Rent</title>
    <link>
    <p>http://www.xxxxxxxxxxxxxxxxx.com</p>
    <br />
    <description>Properties for Rent in Singapore.</description>
    <language>en-us</language>

<?php
   // Connect to the database 
  require_once ('myaccess/dbc.php');

  $rent = 'Rent';

    $query = "SELECT prop_id, prop_cat, add_area, prop_bedroom, prop_bathroom, prop_type, prop_saletype, prop_price, DATE_FORMAT(add_date_orig,'%a, %d %b %Y %T') AS add_date_orig_rfc, " .
    "add_road, prop_desc FROM property_details WHERE prop_cat = $rent 
    ORDER BY prop_type DESC";


  $data = mysqli_query($dbc, $query);

  // Loop through the array of property data, formatting it as RSS
  while ($row = mysqli_fetch_array($data)) { 
    // Display each row as an RSS item
    echo '<item>';
    echo '  <title>' . 'Property ID:' . $row['prop_id'] . ' - ' .  $row['prop_cat'] . ' - ' . 'Property Type:' . ' ' . $row['prop_type'] . ' / ' .  $row['prop_saletype'] .'...</title>';
    echo '  <link>http://www.xxxxxxxxxxxxxxxxxxxxxx.com/propertylisting_details.php?recordID=' . $row['prop_id'] . '</link>';
    echo '  <pubDate>' . $row['add_date_orig_rfc'] . ' ' . date('T') . '</pubDate>';
    echo '  <description><p class="maintextbold10">' . $row['prop_cat'] . ' - ' . $row['add_area'] . $row['prop_bedroom'] . 'Bedrooms' . ' ' .  $row['prop_bathroom'] . 'Bathrooms' . '</p></description><br />';
    echo '  <description><p class="maintextbold10">' . $row['prop_desc'] . '</p></description>';
    echo '</item>';
  }
?>

</channel>
</rss>

However, when I try and open the feed in Outlook Express for example is says: 'Outlook can not process the RSS Feed, feed pointing to an invalid source'

I know this is coincidental, but my almost identical feed without the WHERE clause - Works! ???

Edited by ebanbury

0

Am not sure if this is the cause, but your RSS feed has invalid tags. It could be causing the problems, I've seen it before. If you view the source in the browser, how does it look (with the WHERE clause) ?

Edited by pritaeas: addon

0

use this code

<?php
header("Content-Type: application/rss+xml; charset=ISO-8859-1");
echo '<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
<rss
 xmlns:content="http://purl.org/rss/1.0/modules/content/"
 xmlns:wfw="http://wellformedweb.org/CommentAPI/"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
 xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
 version="2.0">
<channel>
 <title>title</title>
 <link>http://www.sample.com</link>
 <description>Description</description>';
       $connection = @mysql_connect('localhost', 'root', '') or die(mysql_error());
       mysql_select_db('new')  or die (mysql_error()); 
       $query = "SELECT * FROM links order by id desc";
       $rss = mysql_query($query) or die (mysql_error());
       $ImgPath='http://2.bp.blogspot.com/-vwl4cGyoDPM/UqKklyTGE-I/AAAAAAAAALI/iOipE7-PhAM/s1600/logo5.png';
       while($row=mysql_fetch_array($rss)){
       echo ' 
      <item>
      <title>'.$row['name'].'</title>
      <link>'.$row['link'].'</link>  
      <content:encoded>
      <![CDATA[<p align="left">
          <a href="'.$row['link'].'"><img style="background-image: none; " border="0" src="'.$ImgPath.'" />    </a></p>]]>
       </content:encoded>
       <description>'.$row['description'].'</description></item>';
      }
      echo '</channel>
</rss>';
?>

Edited by pritaeas: Removed self-promotion link.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.