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 7921813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:43:33+00:00 2026-06-03T16:43:33+00:00

I have searched but been unable to find anything that does what I need.

  • 0

I have searched but been unable to find anything that does what I need.
I would like to create a stored function that will gather data from a secondary field and return a comma separated list of items as the return string. I can’t seem to find any way to take a variable I create in the function and iterate through a record set and append each result to the variable so I can return it .. see below:

BEGIN
    DECLARE searchCat INT;
    DECLARE searchProd INT;
    DECLARE metas CHAR;
    SET searchCat = cat;
    SET searchProd = prod;
    SELECT * FROM offer_metas WHERE category = searchCat AND offer_id = searchProd
        gatherMeta: LOOP
                metas = metas + "," + meta_option;
                ITERATE gatherMeta;
        END LOOP gatherMeta;
    RETURN metas;
END

The function won’t save because my syntax on the “metas = metas + meta_option;”.
What I am looking for is the command to append the current field falue of “meta_option” to the current variable “metas” so I can return a full list at the end.

Any idea?

UPDATE – SOLUTION

BEGIN
    DECLARE metas VARCHAR (300);

    SELECT GROUP_CONCAT(CONCAT(mn.title,'=',offer_metas.meta_option) ORDER BY mo.cat_seq ASC) INTO metas
    FROM offer_metas
    LEFT JOIN meta_options as mo ON mo.id = offer_metas.meta_option
    LEFT JOIN meta_names AS mn ON mn.category = mo.category AND mn.seq = mo.cat_seq 
    WHERE offer_metas.category = searchCat
    AND offer_metas.offer_id = searchProd
    ORDER BY cat_seq ASC;

    RETURN metas;
END

And then I just updated my SQL query to be as follows (1 is the offer category I have in my PHPand populate into the query):

SELECT offers.*, s.short_name AS sponsorName, s.logo AS sponsorLogo, getMetas(1,offers.id) AS metas 
FROM offers 
LEFT JOIN sponsors AS s ON s.id=offers.carrier 
GROUP BY offers.id 
ORDER BY end_date ASC
  • 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-06-03T16:43:35+00:00Added an answer on June 3, 2026 at 4:43 pm

    Why not just

    SELECT GROUP_CONCAT(meta_option SEPARATOR ',')
    FROM offer_metas
    WHERE category = searchCat AND offer_id = searchProd;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have searched Xcode controls but doesn't found anything that makes a GridView like
I've searched SO and have been unable to find this question asked before, but
I feel like this must have been asked, but I'm unable to find it
I have searched the web and stack overflow questions but been unable to find
I need a CORE that will perform AES-128 Encryption/Decryption. I have searched online but
I have searched, but frustratingly have been unable to figure out why I am
(have searched, but not been able to find a simple solution to this one
I've searched for an answer to this question and have been unable to find
I've searched everywhere but I can't seem to find a solution. I have been
I have searched but have not been able to find any information about this.

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.