Solved

How to use multiple queries based on users selection

Posted on 2014-09-11
2
97 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 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now