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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:56:52+00:00 2026-05-27T04:56:52+00:00

I am using a switch statement on a $_GET variable to produce the result

  • 0

I am using a switch statement on a $_GET variable to produce the result I want on my page.

I am always questioning the best way to run queries in situations like this because I simply do not know the best practice or method. So I have some pseudo code below and I was wondering what the best method would be.

This very well could be a situation where is just doesn’t matter in terms of performance, but if it does I want to make sure I do it right.

if(isset($_GET['type'])){
   $var = $_GET['type'];

  //run the query now and select everything needed from the DB for either switch case. 
  //view implications that involve pulled data
   switch($var){

   case '1':

  //Or do I run the query here, getting only what I need for this situation
  //view implications that involve pulled data
   break;

   case '2':

   //again run the query here, getting only what I need for this situation
   //view implications that involve pulled data

   break;


   }

}

Both cases share one or two similar pieces of data from the DB, but a majority of the content for each case is only needed in that situation.

Bottom line trying to perform the best and keep the code as clean and efficient as possible.

Thanks!

  • 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-27T04:56:53+00:00Added an answer on May 27, 2026 at 4:56 am

    Of course it will be better to only query for data that is relevant to you. There’s no point in tying up the database, transferring more data over the network and then doing more work in PHP to filter out those that do not interest you. So certainly you should not query for “everything”.

    On the other hand, there’s probably no reason to switch either. There has to be a way of rewriting your query such that you can inject the value of a variable into it and, depending on that value, it will return the data you want to in either case. This of course depends also on your database schema.

    No matter what you decide to do, be careful to not expose yourself to SQL injection.

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

Sidebar

Related Questions

What's the best practice for using a switch statement vs using an if statement
How to write following statement in c using switch statement in c int i
For as long as I can remember I have avoided using switch statement fall-through.
What is the benefit/downside to using a switch statement vs. an if/else in C#.
I'm programming a simple text-based RPG using a switch statement for a game loop.
I remember from way back at university using a switch with 'binary search' or
I have an issue with accessing variables initialized in a switch-statement, and then using
currently i'm attempting to using a switch statement to change between time zone with
I get a compiler error when using an Objective-C object within a switch statement:
A few days ago I posted this question: switch statement and loops using jquery/javascript

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.