我有一个查询,它创建了一个图像链接列表,我希望通过这些图像链接的url传递一个变量。但是,因为有多个结果,当我尝试传递它时,我得到的查询乘以了很多结果。
例如,如果$ filter =“sub 1,sub 2”并返回三个图像,则传递_filter =“sub1,sub2,sub1,sub2,sub1,sub2”
所以我要做的就是传递_filter =“sub1,sub2”。
$ filter从多选下拉列表中传递。而且pass_filter是$ filter被发送回结果页面的结果。
关于如何更改下面的代码以实现我想要的任何想法?
php页面:
<?php
echo "<h2>Currently Displaying: Custom Selection</h2>";
include ("connect.php");
$filter = $_GET["filter"];
$filterIn = $filter;
$result = mysql_query("SELECT * FROM edt_images
WHERE cat1 IN ($filterIn)
OR cat2 IN ($filterIn)
OR cat3 IN ($filterIn)
OR cat4 IN ($filterIn)
OR cat5 IN ($filterIn)
OR cat6 IN ($filterIn)
ORDER BY vote_item_id")
or die(mysql_error());
echo "<div id='results_container'>";
echo "<ul id='items'>";
while ($row = mysql_fetch_array($result)) {
echo "<li><a href='subpage.php?passed_filter=".$filter."&id=".$row['id']."' border='0'>
<img src='files/300x200/thumb2_".$row['item_name'].".".$row['file_extension']."' border='0' class='filtered_images'/>
</a>
<br />
<strong>
".$row['file_tag_line']."
</strong>
</li>";
}
echo "</ul>";
echo "</div>";
?>
提前致谢。如果我还需要发布任何其他内容,请告诉我。
答案 0 :(得分:1)
mysql_
函数CREATE TABLE edit_images_category (
id tinyint,
category varchar(10),
PRIMARY KEY (id, category));
INSERT INTO edit_image_category (id, category)
SELECT id, cat1 AS cat FROM edit_images
UNION ALL
SELECT id, cat2 AS cat FROM edit_images
UNION ALL
SELECT id, cat3 AS cat FROM edit_images
UNION ALL
SELECT id, cat4 AS cat FROM edit_images
UNION ALL
SELECT id, cat5 AS cat FROM edit_images
UNION ALL
SELECT id, cat6 AS cat FROM edit_images
SELECT * FROM edit_images_category WHERE cat IN ($filterIn)