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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:13:02+00:00 2026-06-13T08:13:02+00:00

New to sql and php and trying to work through this one. After reading

  • 0

New to sql and php and trying to work through this one. After reading several examples here, I still can’t seem to get this done. Right now I have the following query

$sql = "SELECT e.id, e.event_name, e.recurrence_id, e.start_date, e.venue_title FROM " . wp_events_detail . " e  WHERE e.recurrence_id <>0 or e.recurrence_id = 0 and is_active = 'Y' GROUP BY e.event_name, e.start_date"  ;
                $posts = $wpdb->get_results($sql);

                print("<ul>");
                foreach ($posts as $post)
                {
                    print('<li>'.$post->event_name.'|'.$post->event_desc.'<br/>');

                     print('</li>');
                    print($post->start_date. '~' .$post->venue_title.'<br/>'); 
                }
                print("</ul>");

This produces
Name of Class A
Start Date 1
Name of Class A
Start Date 2
Name of Class B
Start Date 1
Name of Class B
Start Date 2

what I would like is
Name of Class A
Start Date 1
Start Date 2

Name of Class B
Start Date 1
Start Date 2

I know I need an array and define rows – Have tried several options with no luck. Not understanding all the variables etc defined in this answer (which seems what I want this to do)

Show year only once in archives loop

Any help greatly appreciated! Even a point in the right direction;-)

  • 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-13T08:13:03+00:00Added an answer on June 13, 2026 at 8:13 am

    you can adjust your for loop to be:

    $lastseeneventname='';
    foreach ($posts as $post){
       if($lastseeneventname!=$post->event_name){
          print('<li>'.$post->event_name.'|'.$post->event_desc.'<br/>');
          print('</li>');
          $lastseeneventname=$post->event_name;
       }
       print($post->start_date. '~' .$post->venue_title.'<br/>'); 
    }
    

    This will only print new event_names once which is what, I think, you want.

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

Sidebar

Related Questions

I'm trying to add new entries to an sql database using php, i can
I am new to the whole php, sql, jquery. I am trying to paginate
I'm not sure why this SQL query is not working. I'm new to SQL/PHP
I'm trying to make a PHP (5) object that can iterate through its properties,
im very new to this and have a very basic knowledge php and SQL
I am new to php and SQL so this is probably an easy question
im new in php sql and stuff, and I've been trying to think in
In PHP I am having difficulty trying to extract row data from one SQL
Alright, so I'm fairly new to PHP and SQL/MySQL so any help is appreciated.
I'm relatively new SQL queries, and I'm trying to join two tables in order

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.