Solved

How to use multiple queries based on users selection

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

631 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