Solved

How to use multiple queries based on users selection

Posted on 2014-09-11
2
103 Views
Last Modified: 2014-09-15
I have a highcharts chart im using to display number of downloads on apps. The chart is being populated by mysql query.

I have 2 bootstrap dropdown-menu's for that chart. one is date range, and the other is app. The app is populated by a sql query.

Each one of these dropdown's work fine independently. i want them to work together. So if the user chooses a app then a date it will keep track of both.

Here is how im handling the $GET's now

if (isset($_GET['id'])) {
    $app = $_GET['id'];
    $array2 = explode('/', $app);
    $activity = $array2[0];
    $app_name = $array2[1];
    $SQL= " SELECT blah blah blah WHERE activity = ' $activity' ";
} else if (isset($_GET['date'])) {
      $daterange = $_GET['date'];
              if ($daterange = "thisyear"){
               $SQL =
               }
              if ($daterange = "lastyear"){
               $SQL =
               }
} else {
    $SQL = 
}

Open in new window


I can provide more info if needed.
0
Comment
Question by:bignadad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 40317562
$SQL = "SELECT blah blah blah WHERE ";
if (isset($_GET['id'])) {
    $app = $_GET['id'];
    $array2 = explode('/', $app);
    $activity = $array2[0];
    $app_name = $array2[1];
    $SQL .= "activity = ' $activity' ";
}
if (isset($_GET['date'])) {
	$daterange = $_GET['date'];
	if ($daterange = "thisyear"){
	 $SQL .= "AND date = 'thisyear'"; //whatever date value needs to be for this year
	 }
	if ($daterange = "lastyear"){
	 $SQL .= "AND date = 'lastyear'"; //whatever date value needs to be for last year
	 }
} 

Open in new window

0
 
LVL 2

Author Comment

by:bignadad
ID: 40317768
okay. I understand this and will work well.

However, you put the WHERE on the first line of $SQL. when table initially loads it won't have a where clause.

Also you put AND if $_GET date exists. What if there is only app chosen and no date? or date and no app?
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Node.js 11 82
e commerce steps shown instead of self testing 2 59
Mysql query one to many 11 42
Secure registration PHP 7 43
Creating and Managing Databases with phpMyAdmin in cPanel.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question