Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use multiple queries based on users selection

Posted on 2014-09-11
2
Medium Priority
?
109 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
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

927 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