Reputation: 431
I have a query which creates a list of image-links, I want to pass to pass a variable through the url of these image links. However, because there are multiple results, when I try to pass it, I get the query multiplied by however many results there are.
For example if $filter = "sub 1, sub 2" and that returns three images, then passed_filter = "sub1, sub2, sub1, sub2, sub1, sub2"
So what I'm trying to make it do is passed_filter = "sub1, sub2".
$filter is passed from a multiselect dropdown. And passed_filter, is the results from $filter getting sent back to the results page.
Any ideas on how I could change the code below to do what I want?
The php page:
<?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>";
?>
Thanks in advance. Please let me know if there is anything else I need to post.
Upvotes: 0
Views: 64
Reputation: 34063
mysql_
functionsCREATE 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)
Upvotes: 1