Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:14:14+00:00 2026-05-29T15:14:14+00:00

I am trying to retrieve tags that are associated with a society. The code

  • 0

I am trying to retrieve tags that are associated with a society. The code below works, but it is only retrieving the first tag and not the rest in the table.

$user = $_SESSION['user'];
$society = $_SESSION['society'];

$soc_q = mysql_query("SELECT socID, creator, socName, type, datetime
     FROM societies.society WHERE socName = '$society'");
$soc_row = mysql_fetch_array($soc_q, MYSQL_ASSOC);


$tag_q = mysql_query("SELECT society.socID, tagID, name
     FROM societies.society
     INNER JOIN societies.tags ON society.socID = tags.socID
     WHERE society.socID = '$soc_row[socID]'");
$tag_row = mysql_fetch_array($tag_q, MYSQL_ASSOC);

$the_tags = $tag_row['name'];

if (!@$_SESSION['existing_tags']) {
    $_SESSION['existing_tags'] = $the_tags;
}

$existing_tags = $_SESSION['existing_tags'];
$tags = explode(' ', $the_tags);

// ajax
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && @$_GET['tag']) {
    $match = array();
    foreach ($tags as $tag) {
        if (stripos($tag, $_GET['tag']) === 0) {
            $match[] = $tag;
        }
    }

    echo json_encode($match);

    exit;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:14:15+00:00Added an answer on May 29, 2026 at 3:14 pm

    You have to load tags in loop like this (get each row):

    $the_tags = array();
    while( $tag_row = mysql_fetch_assoc( $tag_q)){
        $the_tags[] = $tag_row['name'];
    }
    

    Edit: using GROUP BY

    If you are willing to play with mySQL and element grouping you may use GROUP_CONCAT (if you need only tag names):

    $tag_q = mysql_query("
         SELECT GROUP_CONCAT( DISTINCT tags.name SEPARATOR ', ') as `tags`
         FROM societies.society
         INNER JOIN societies.tags ON society.socID = tags.socID
         WHERE society.socID = '$soc_row[socID]'
         GROUP BY NULL");
    $tag_row = mysql_fetch_array($tag_q, MYSQL_ASSOC);
    $tag_names = explode( ', ', $tag_row['tags']);
    

    The code above isn’t that useful, but when you’ll combine it with your first query, you’ll get:

    $soc_q = mysql_query("SELECT socID, creator, socName, type, datetime,
         GROUP_CONCAT( DISTINCT tags.name SEPARATOR ', ') as `tags`
         FROM society
         LEFT JOIN societies On societies.socID = society.socID
         LEFT JOIN tags ON societies.tagsID = tags.socID
         WHERE socName = '$society'
         GROUP_BY society.id");
    $soc_row = mysql_fetch_array($soc_q, MYSQL_ASSOC);
    

    Note: prefixing tables with database names makes your code hard to read because once you’re doing that, other time not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
Trying to retrieve blogs (see model description below) that contain entries satisfying some criteria:
I'm trying to retrieve specific tags with their content out of an xhtml document,
I am trying to retrieve the attribute name and type that exist in an
I'm trying to retrieve the SubItem in my ListView from another thread, but I
I'm trying to make a set of custom tags that encapsulate form elements (markup
I'm trying to retrieve all rows inserted during a specific month. SELECT dbo.Post.UserId, dbo.Post.Tags,
I'm trying to make a script that scrapes a website to retrieve the latest
I am trying to retrieve the slug for a tag inside a wordpress post,
I am trying to find a way to retrieve a users zip code based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.