0

I have an RSS feed I created pulling data from three tables in SQL. I would like to add more then one image to the item description but not sure how to add the additional image without it repeating the first image? Here is what I have done so far with two image links but both links show same image:

$query = "SELECT 1j0_cddir_jomestate.title, 1j0_cddir_jomestate.fulltext, 1j0_cddir_jomestate.categories_address_id, 1j0_cddir_categories.path, 1j0_cddir_categories.id, 1j0_cddir_jomestate.alias, 1j0_cddir_jomestate.id, 1j0_cddir_images.content_id, 1j0_cddir_images.name, 1j0_cddir_images.path as pathy, 1j0_cddir_images.id as idy ".
                        "FROM 1j0_cddir_jomestate, 1j0_cddir_categories, 1j0_cddir_images ".
                        "WHERE 1j0_cddir_jomestate.categories_address_id = 1j0_cddir_categories.id AND 1j0_cddir_jomestate.id = 1j0_cddir_images.content_id ".
                        "ORDER BY 1j0_cddir_jomestate.id ASC ".
                        "LIMIT 10";
$result = mysql_query($query) or die ("Could not execute query");


    while($row = mysql_fetch_array($result)) {
        extract($row);
        $rssfeed .= '<item>';
        $rssfeed .= '<title>' . htmlspecialchars($row['title'],ENT_IGNORE) . '</title>';
        $rssfeed .= '<description><![CDATA[<img src="/components/com_jomcomdev/images/' . $row['pathy'] . '/' . $row['name'] . '"/><img src="/components/com_jomcomdev/images/' . $row['pathy'] . '/' . $row['name'] . '"/>' . htmlspecialchars($row['fulltext'],ENT_IGNORE) . ']]></description>';
        $rssfeed .= '<link>http://localhost/cprop/for-sale/' . $row['path'] . '/' . $row['id'] . '-' . $row['alias'] . '</link>';
        $rssfeed .= '</item>';
    }
    $rssfeed .= '</channel>';
    $rssfeed .= '</rss>'; 

    echo $rssfeed;
?>
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • You shouldn't use `mysql_` functions as they are [deprecated](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Mar 28 '15 at 00:01

1 Answers1

0

Your SQL query is going to return only one image for each record. If there is more than one image, it would create multiple rows in the response.

The easiest solution to this would be to break it into two queries.

Query 1

$query = "SELECT 1j0_cddir_jomestate.title, 1j0_cddir_jomestate.fulltext, 1j0_cddir_jomestate.categories_address_id, 1j0_cddir_categories.path, 1j0_cddir_categories.id, 1j0_cddir_jomestate.alias, 1j0_cddir_jomestate.id".
  FROM 1j0_cddir_jomestate, 1j0_cddir_categories ".
 "WHERE 1j0_cddir_jomestate.categories_address_id = 1j0_cddir_categories.id ".
 "ORDER BY 1j0_cddir_jomestate.id ASC ".
 "LIMIT 10";

Then, after you retrieve your row, do a second query:

$query = "SELECT 1j0_cddir_images.content_id, 1j0_cddir_images.name, 1j0_cddir_images.path as pathy, 1j0_cddir_images.id as idy ".
"FROM 1j0_cddir_jomestate, 1j0_cddir_images ".
"WHERE 1j0_cddir_jomestate.id = 1j0_cddir_images.content_id ".
"LIMIT 10";

And then you can loop through the results of that, outputting an image tag to the RSS output for each row of the second results.

Joel
  • 237
  • 3
  • 9