I use a while loop to echo member data to display each member's listing. I then use Jquery to filter the listings according to value(s) which are echoed from the items
field. (i.e. the items
field may contain "item1 item3 item10").This works well!!! Here's the code I have now.
<?php
$area = "Richmond";
$db_connect = @mysqli_connect("localhost", "user", "password","database");
if (mysqli_connect_errno($db_connect)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = @mysqli_query($db_connect, "SELECT * FROM database WHERE territories LIKE '%$area%'");
if (!$result){
echo ("<p>Error performing listing query:" . mysql_error() . "</p>");
}
$items = array();
while ($row = mysqli_fetch_array($result)){
// Jquery uses these "$row["items"]" for it's filter
$items[] = "<li class=\"services " . $row["items"] . "\">
// more code here used to construct member's listing
}
?>
//In the html, I echo each member's completed listing...
<?php echo $items[0]; echo $items[1]; echo $items[2]; etc... ?>
How can I set an echo limit to 12 duplicate value(s) from the items
field? There are only 12 listings available for each value in items
. So I want only the first 12 of each value to be included in the echo. If a member cancels, then items
value(s) from next member will be echoed automatically. I hope this makes sense! :D
[EDIT] For more clarity, lets say 12 members list for "item1 item2" (both are in the items
field). With the current code, the html for each listing would read <li class="services item1 item2"></li>
.
Then a 13th member lists his services of "item1 item2 item3". Since "item1" and "item2" exist 12 times, only item3 should echo. This new member's listing should read <li class="services item3"></li>
. If a previous member cancels, all three items would be echoed.
I picture something like if COUNT(items=%item1%) <= 12)
or something similar... I can't seem to wrap my mind around using GROUP BY
or DISTINCT
with my current set up.