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

  • SEARCH
  • Home
  • 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 7506685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:19:57+00:00 2026-05-29T22:19:57+00:00

Basically I do while two time to get main group & group value. Example

  • 0

Basically I do while two time to get main group & group value. Example

$group_query = $db->query("
        SELECT opt_id, opt_type 
            FROM ads_options 
            WHERE opt_id = '" . intval($data['ad_id']) . "'
            GROUP BY opt_type");
while ($group_data = $db->fetch($group_query)) {
    $option_query = $db->query("
        SELECT * 
            FROM ads_options 
            WHERE opt_id = '" . intval($data['ad_id']) . "' 
            AND opt_type ='" . $group_data['opt_type'] . "'
            ORDER BY opt_id DESC");
    while ($option_data = $db->fetch($option_query)) {
    }
}

Output :

Size   : S
         M
         L  
Color  : White
         Black

Question :

How to join current queries above with single statement?

Update :

Current database structure

opt_id  opt_type  opt_name  opt_price
1236    Size      S         0
1236    Size      M         1
1236    Color     Black     1
1236    Color     White     2
  • 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-29T22:19:58+00:00Added an answer on May 29, 2026 at 10:19 pm

    Something like this would get the unique combinations, may be of help

    $group_query = $db->query("
        SELECT
            DISTINCT opt_id, opt_type, opt_size
        FROM ads_options 
        WHERE opt_id = " . intval($data['ad_id']) . "
        ORDER BY opt_type, opt_size");
    

    If you are able to supply more details as to precisely what you are trying to achieve, and the full design of ads_options, then it would be easier to provide more specific advice

    Also a minor note, if opt_id is numeric then you don’t need single quotes (‘) around it within the query (so removed them in example)

    EDIT
    Something like the following would return you a list of id, type, and then as third field a comma-delimited list of values, if that’s of more help

    $group_query = $db->query("
        SELECT
            opt_id, opt_type, GROUP_CONCAT(opt_name) AS opt_names
        FROM ads_options 
        WHERE opt_id = " . intval($data['ad_id']) . "
        ORDER BY opt_type");
    

    For more information on GROUP_CONCAT check out this link http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

    I’ve no idea if PHP programatically has something to help with this, I tend to use Coldfusion so if anyone knows of a PHP version of doing the following then that seems to match what OP was asking for

    <cfoutput query="qryAdOptions" group="opt_type">
        #qryAdOptions.opt_type#
        <cfoutput>
            #qryAdOptions.opt_name#
        </cfoutput>
    </cfoutput>
    

    http://bytes.com/topic/php/answers/11929-grouping-results-query#post50606 seems to suggest the following as potentially a match for the I posted above so may be useful

    $answer = array();
    while ($row = pg_fetch_array($results)) {
      if (!isset($answer[$row["obj_type"]])) {
        $answer[$row["obj_type"]] = array();
      }
      $answer[$row["obj_type"]][] = $row;
    }
    

    You then iterate over $answer. This would play nicely with

    SELECT * FROM ads_options WHERE opt_id = ......
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most of the longest (most time-consuming) logic I've encountered basically involves two things: sending
basically, i was wiresharking packets on my PS3 while viewing Motorstorm Leaderboards. The leaderboards
I'm getting an Illegal characters in path error while using XMLTextReader method. Basically, I'm
I want to implement an SSL proxy in Java. I basically open two sockets
I'm having a bit of a frustrating time with a SQL query and could
I've got two Jquery functions that I can get to work fine alone on
Basically this is my code: bay=$(prog -some flags) while [ $bay = Another instance
I have two web pages which work basically the same, code-wise, but one of
I'm having a little problem using NSURLDownload . Basically I'm downloading two different files
I have two tables linked by a foreign key. Example: CREATE TABLE one (id

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.