0

Hi,

I have searched high and low and cant find a similar issue to what i have.

I am a beginner so please forgive my clunky query structure.

I am trying to: ( have attached screen grab below )

Query the photos table to get the id based on category id and also start,limit because of pagination.

Query the photos tagged table based on the photo id i just got from the first query.

But my problem is that i cant group the tags, some photos have the same tag name. And the output just shows all the tags for each photo. I want restaurant to show only once etc...

<?php
// Get the file ideez and dont go beyond pagination start,limit eg:30,10       

$queryFile = "SELECT id FROM $tableName WHERE cat_id=".$fileID."  LIMIT $start, $limit";
$resultFile = mysql_query($queryFile);
while ($rowFile = mysql_fetch_array($resultFile)) { 

// Get the tag names based on the file ideez retrived from the above query   

$queryTagged = "SELECT tag_name FROM photoTagged WHERE file_id=".$rowFile['id']." GROUP BY tag_name";
$resultTagged = mysql_query($queryTagged) or die(mysql_error()); 
while ($rowTagged = mysql_fetch_array($resultTagged)) { 
$tagged = $rowTagged['tag_name'];

?>

<li><a href="#"><?php echo $tagged; ?></li>

<?php }} ?>

the above query is producing:

bar,cappucino,coffee,coffee machine,restaurant,bar,cappucino,coffee,coffee machine,restaurant,bar,coffee,restaurant,bar,coffee,coffee machine
restaurant,bar,cappucino,coffee,restaurant

what i need to show is: bar,cappucino,coffee,coffee machine,restaurant If anyone could help i would greatly appreciate it.

Thank you in advance.

John

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by diafol
0

You want a 'running array'. Do photos have more than one tag term? If not:

$tags = array();
while($rowTagged = mysql_fetch_array($resultTagged)){
 $add_candidate = $rowTagged['tag_name'];
 if(!in_array($add_candidate,$tags))array_push($tags,$add_candidate);
}
$tag_output = implode(',',$tags);
//OR $tag_output = implode('<br />',$tags);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.