Jump to content

[SOLVED] Combining four if statements


karenn1

Recommended Posts

I have three dropdowns on my page that filters a search. I have four if statements to determine whether  a value was selected in the dropdown. Independatly, all four of them work on their own but as soon as I place them all on the same page, any search I do just returns all results. My code below:

 

// Region = All, Rep = All, Outlet = All
	if (($_REQUEST['areas'] = 'All') && ($_REQUEST['reps'] = 'All') && ($_REQUEST['outlets'] = 'All')) {
	$sql_prop = "SELECT Venue_Region, CONCAT(TMR_Name, ' ', TMR_Surname) AS Name,Venue_Name, SUM(Quantity) AS Quantity, SUM(Value_Cost) AS Income
				FROM web_summary_info
				WHERE Trans_Date BETWEEN '".$from_date."' AND '".$to_date."'
				GROUP BY Venue_Region,(TMR_Name + ' ' + TMR_Surname), Venue_Name";
	$result_prop = mysql_query($sql_prop);
	} 

	// Region = Selected, Rep = All, Outlet = All
	if (($_REQUEST['areas'] != 'All') && ($_REQUEST['reps'] = 'All') && ($_REQUEST['outlets'] = 'All')) {
	$areas = $_REQUEST['areas'];
	$sql_prop = "SELECT Venue_Region, CONCAT(TMR_Name, ' ', TMR_Surname) AS Name,Venue_Name, SUM(Quantity) AS Quantity, SUM(Value_Cost) AS Income
				FROM web_summary_info
				WHERE Trans_Date BETWEEN '".$from_date."' AND '".$to_date."'  AND Venue_Region = '".$areas."'
				GROUP BY Venue_Region,(TMR_Name + ' ' + TMR_Surname), Venue_Name";
	$result_prop = mysql_query($sql_prop);
	} 

	// Region = Selected, Rep = Selected, Outlet = All
	if (($_REQUEST['areas'] != 'All') && ($_REQUEST['reps'] != 'All') && ($_REQUEST['outlets'] = 'All')) {
	//$name = $_POST['Name'];
	$areas = $_REQUEST['areas'];
	$reps = $_REQUEST['reps'];
	$sql_prop = "SELECT Venue_Region, CONCAT(TMR_Name, ' ', TMR_Surname) AS Name, Venue_Name, SUM(Quantity) AS Quantity, SUM(Value_Cost) AS Income
				FROM web_summary_info
				WHERE Trans_Date BETWEEN '".$from_date."' AND '".$to_date."'  AND Venue_Region = '".$areas."' AND TMR_Code = '".$reps."'
				GROUP BY Venue_Region,(TMR_Name + ' ' + TMR_Surname), Venue_Name";
	$result_prop = mysql_query($sql_prop);
	} 

	// Region = Selected, Rep = Selected, Outlet = All
	if (($_REQUEST['areas'] != 'All') && ($_REQUEST['reps'] != 'All') && ($_REQUEST['outlets'] != 'All')) {
	//$name = $_POST['Name'];
	$areas = $_REQUEST['areas'];
	$reps = $_REQUEST['reps'];
	$outlets = $_REQUEST['outlets'];		
	$sql_prop = "SELECT Venue_Region, CONCAT(TMR_Name, ' ', TMR_Surname) AS Name, Venue_Name, SUM(Quantity) AS Quantity, SUM(Value_Cost) AS Income
				FROM web_summary_info
				WHERE Trans_Date BETWEEN '".$from_date."' AND '".$to_date."'  AND Venue_Region = '".$areas."' AND TMR_Code = '".$reps."' AND Venue_ID = '".$outlets."'
				GROUP BY Venue_Region,(TMR_Name + ' ' + TMR_Surname), Venue_Name";
	$result_prop = mysql_query($sql_prop);
	}

 

Like I said, independantly it works great but I need it combined. My dropdowns look as follows:

 

<select name="areas" id="areas" onchange="window.document.searchform.submit();">
                  <option value="All" selected="selected">Select First</option>
		    
                  <?php
	  			
				while ($rs_dd1 = mysql_fetch_array($result_dd1))	{
					print "<option value=\"".$rs_dd1["Venue_Region"]."\">".ucwords($rs_dd1["Venue_Region"])."</option>";
				}
	  		   ?>		        
                </select>

 

<select name="reps" id="reps" onchange="window.document.searchform.submit();">
                 <option value="All" selected="selected">Select Second</option>
                  
                 <?php
	  			
				while ($rs_dd2 = mysql_fetch_array($result_dd2))	{
					print "<option value=\"".$rs_dd2["TMR_Code"]."\">".ucwords($rs_dd2["Name"])."</option>";
				}
	  		   ?>
			   
                </select>

 

<select name="outlets" id="outlets">
                  <option value="All" selected="selected">Select Third</option>
                  <?php
	  			
				while ($rs_dd3 = mysql_fetch_array($result_dd3))	{
					print "<option value=\"".$rs_dd3["Venue_ID"]."\">".ucwords($rs_dd3["Venue_Name"])."</option>";
				}
	  		   ?>
                </select>  

 

I know I've been a bit of a nuisance on these forums but can anybody help?

 

 

Thanks,

 

Karen

Link to comment
Share on other sites

You need to use 2 equals if your evaluating that both sides are the same as each other

 

So this:

if (($_REQUEST['areas'] = 'All') && ($_REQUEST['reps'] = 'All') && ($_REQUEST['outlets'] = 'All'))

 

Becomes:

if (($_REQUEST['areas'] == 'All') && ($_REQUEST['reps'] == 'All') && ($_REQUEST['outlets'] == 'All'))

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.