I've been breaking my head with a basic php if statement logic error for hours...
What I need to achieve is simple. I have 2 dropdown boxs, the first box 'value Range' filters the data from DB, default value is none. The second box 'sort Value' sorts the data asc or desc, default value is 0.
If sort value is selected. I need my second if statement to be executed, which fails!...
Code: Select all
<tr>
<td class="tblSTD tblTHBL tblTHBT">USD Value Range </td>
<td class="tblSTD tblTHBR tblTHBT"><select id="valueRange" name="valueRange">
<option value="Select">ALL</option>
<option value="0.01" <?php if($valueRange=="0.01") echo "selected='selected'";?>> < $1 </option>
<option value="1" <?php if($valueRange=="1") echo "selected='selected'";?>>$1 to $3</option>
<option value="3" <?php if($valueRange=="3") echo "selected='selected'";?>>$3 to $5</option>
<option value="5" <?php if($valueRange=="5") echo "selected='selected'";?>>$5 to $10</option>
<option value="11" <?php if($valueRange=="11") echo "selected='selected'";?>> >$10</option>
</select></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="24"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td class="tblSTD tblTHBL tblTHBB">Sort (Value Range) </td>
<td class="tblSTD tblTHBR tblTHBB"><select id="sortValue" name="sortValue">
<option value="0" >None</option>
<option value="asc" <?php if($sortValue=="asc") echo "selected='selected'";?>>Ascending</option>
<option value="desc" <?php if($sortValue=="desc") echo "selected='selected'";?>>Descending</option>
</select></td>
<td> </td>
<td><input type="submit" name="GO" value="GO" style=" font-weight: bold; color: #ffffff; background: #ff6600;"/></td>
</tr>
Code: Select all
echo "valueRange ".$valueRange."<br>";
echo "sortValue ".$sortValue."<br>";
if($sortValue == "" || $sortValue == 0){
echo "sortValue=' ' r 0 ".$sortValue."<br>";
$Orderby = "Region, Country, CategoryName, BeneficiaryName";
}elseif($sortValue == "asc" || $sortValue == "desc"){
echo "sortValue_Inside ".$sortValue."<br>";
$Orderby = "CostUSD $sortValue, Region, Country, CategoryName, BeneficiaryName";
}
echo "Orderby ".$Orderby."<br>";
$query = "SELECT Title, ID, s.OrgJosUserID, OrgName, r.Region, Country, Story, PicURL, CostUSD, b.BeneficiaryName, c.CategoryName
FROM tbl s
INNER JOIN jos_users js ON js.id = s.OrgJosUserID
INNER JOIN tbl_regions r ON r.RegionID = s.RegionID
INNER JOIN tbl_categories c ON c.CategoryID = s.CatID
INNER JOIN tbl_beneficiary b ON b.BeneficiaryID = s.BeneficiaryID
WHERE r.Region LIKE '$regionList' AND c.CategoryName LIKE '$categoryList'
AND b.BeneficiaryName LIKE '$beneficiaryList'
AND CostUSD BETWEEN '$valueRange1' AND '$valueRange2'
ORDER BY $Orderby ";
The output I get for echo are:
valueRange: 1
sortValue: asc
sortValue='' r 0: asc
Orderby: Region, Country, CategoryName, BeneficiaryName
Any idea were I'm going wrong?
Thanks