在 PHP SQL RSS 中向项目描述添加不止一张图片

Adding more then one image to item description in PHP SQL RSS

我有一个 RSS 提要,是我从 SQL 中的三个表中提取数据而创建的。我想在项目描述中添加多张图片,但不确定如何在不重复第一张图片的情况下添加附加图片?这是我到目前为止对两个图片链接所做的,但两个链接显示相同的图片:

$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;
?>

您的 SQL 查询将 return 每条记录仅查询一张图像。如果有不止一张图片,它会在响应中创建多行。

最简单的解决方案是将其分成两个查询。

查询 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";

然后,在您检索到您的行后,执行第二个查询:

$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";

然后你可以遍历它的结果,为第二个结果的每一行输出一个图像标签到 RSS 输出。