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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:00:52+00:00 2026-06-16T02:00:52+00:00

Can anyone help me simplify this? I have a page for viewing a bunch

  • 0

Can anyone help me simplify this? I have a page for viewing a bunch of data from a table, the page is supposed to accept different values via GET calls. I’d just like to slim it down a bit. Again, the code works, it’s just spaghetti to me.

if(!$_REQUEST['foo']){
    $bar = $_REQUEST['bar'];
    if($bar=='all'||!$bar){ $stmt = "SELECT * FROM table
        WHERE qty > 0  and
             somedate >= \"{$start}\"  and
             somedate <= \"{$end}\"
        ORDER BY id desc
        ";}
    else{
    $stmt = "SELECT * FROM table
        WHERE qty > 0  and
             somedate >= \"{$start}\"  and
             somedate <= \"{$end}\"  and
             bar = '$bar'
        ORDER BY id desc
        ";}
}
else{
     switch($_REQUEST['foo']){
       case 'all':
        $stmt = "SELECT * FROM table
          WHERE qty > 0  and
          somedate >= \"{$start}\"  and
          somedate <= \"{$end}\"
          ORDER BY id desc";
        break;
     case 'open':
      $stmt = "SELECT * FROM table
          WHERE qty > 0  and
          closd = 0 and
          somedate >= \"{$start}\"  and
          somedate <= \"{$end}\"
          ORDER BY id desc";
      break;
     case 'closed':
      $stmt = "SELECT * FROM table
          WHERE qty > 0  and
          closd = 1 and
          somedate >= \"{$start}\"  and
          somedate <= \"{$end}\"
          ORDER BY id desc";
      break;
}}
  • 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-16T02:00:53+00:00Added an answer on June 16, 2026 at 2:00 am

    This would handle the switch() assuming you have some sanity checks in the program.

    <?php // RAY_temp_andy_foster.php
    error_reporting(E_ALL);
    
    $closd = '1=1';
    switch($_REQUEST['foo'])
    {
        case 'all':    $closd = '1=1';       break;
        case 'open':   $closd = 'closd = 0'; break;
        case 'closed': $closd = 'closd = 1'; break;
    }
    $stmt = "SELECT * FROM table WHERE qty > 0 AND somedate >= \"{$start}\"  AND somedate <= \"{$end}\" AND $closd ORDER BY id desc";
    

    var_dump($stmt);

    HTH, ~Ray

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

Sidebar

Related Questions

Can anyone help me on creation of comparison matrix from mySQL table. I have
Can anyone help me with this problem please? I have 2 databases on the
Can anyone help. I am using a formview in VS 2005. I have different
Can anyone help with this I really can't see what is wrong. I have
Can anyone help me with this? I have this function in a singleton class.
Can anyone help me figure out how I could simplify this code, without using
Can anyone help me to find out why this page looks fine in FireFox
Can anyone help, how to retrieve exactly 2nd row from the table in oracle?
can anyone help, I have an issue with the keyword this.. before entering the
Can anyone help me with this one I have this query and only after

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.