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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:03:36+00:00 2026-05-28T17:03:36+00:00

ok; this has been frying my brain for hours. I think I might need

  • 0

ok; this has been frying my brain for hours. I think I might need a sub query, but I’m not that advanced at this kind of thing so any help or pointers in the right direction would be greatly appreciated.

Here’s the Query I have….

$query = "SELECT * FROM events WHERE event_type = 'Christmas Listings' AND event_active='Yes' ORDER BY event_date ASC LIMIT 5";
$result= mysql_query($query); 

OK… now for the plain english bit on what I want to achieve (to understand what I’m trying to achieve):

  1. I want to check the event type (‘event_type‘) is what I’m getting (ie. Christmas Listings) as there are multiple types in this column.

  2. I want to check the event is active (‘event_active‘) is Yes(the data in this field is Yes/No).

  3. I want to order them by the (‘event_date‘) ASC (the data in this field is yyyy-mm-dd) so they show the latest entry by its date from the DB.

  4. I want to LIMIT (or in some way control the output) the results to only have 5 results displayed when running this kind of query through a WHILE statement.

OK, this all works BUT; when I get to the actual output display, i’m having a shaky output in how many results are actually display… What happens is if I have multiple events which are switched off, as in event_active is ‘Off‘ then its almost like the argument is counting from the all the results that are (including event_active='Off') and consequently not showing how I expect them to display?

Hope this makes sense…. Any help would be gratefully received.

  • 1 1 Answer
  • 1 View
  • 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-28T17:03:37+00:00Added an answer on May 28, 2026 at 5:03 pm
    SELECT * 
    FROM events 
    WHERE event_type = 'Christmas Listings' AND event_active='Yes' 
    ORDER BY event_date 
    LIMIT 0, 5
    

    so your statement is easyer to read..

    1. You shoul use 1 / 0 instead of Yes / no
    2. The Limit does not count all lines!
      First step – doing the query including WHERE
      Second step – ORDER BY
      Third step – LIMIT
      If you have set an index on the colum you sort. The sort will stop after 5 lines,
      also means – it get faster
    3. The ASC in the ORDER BY command is not necessary, because ASC is default
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me nuts. I hope it's not been asked before but
This has been asked before , but even after implementing that solution, problems remain.
This has been asked few times but I think it's still worth checking with
This has been asked many times. But most answers are not applicable to the
This has been killing me - I have a massive file that I need
This has been asked before, but was not clarified to the point where I
This has been stressing me out. I'm calling a php function that saves an
This has been asked before but I can't find a definitive answer, in code.
This has been asked a couple of times, but none provide coded test cases.
I know this has to be a duplicate, but I've been wading through the

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.