dflow Posted December 23, 2009 Share Posted December 23, 2009 i have this query <?php $query_RsSideRatingloop = sprintf("SELECT products.ProductID, ratings_tbl.ProductID, FROM ratings_tbl, products WHERE ratings_tbl.CityID =%s AND products.ProductID = ratings_tbl.ProductID ORDER BY RAND() LIMIT 0 , 3", GetSQLValueString($colname_RsSideRatingloop, "int")); $RsSideRatingloop = mysql_query($query_RsSideRatingloop, $international) or die(mysql_error()); $row_RsSideRatingloop = mysql_fetch_assoc($RsSideRatingloop); $totalRows_RsSideRatingloop = mysql_num_rows($RsSideRatingloop);?> the result should be true if the $parameter(echoed correctly and works as single condition in the switch when i add and check if the query returns 0 with $totalRows_RsSideRatingloop which is echoed correctly too when combined the default switch case is echoed <?php switch (true) { case ($parameter='CountryID' and $totalRows_RsSideRatingloop>0) : require_once('side-loop-CountryID.php'); break; case ($parameter='CityID' and $totalRows_RsSideRatingloop>0) : require_once('side-loop-CityID.php'); break; case ($parameter='RegionID' and $totalRows_RsSideRatingloop>0) : require_once('side-loop-RegionID.php'); break; default: echo 'empty'; } ?> Link to comment https://forums.phpfreaks.com/topic/186175-help-with-switch-2-parameters/ Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 If one of your cases return true, all will return true as assigning a value to a variable is always true. I think you are wanting $parameter==Value Link to comment https://forums.phpfreaks.com/topic/186175-help-with-switch-2-parameters/#findComment-983233 Share on other sites More sharing options...
dflow Posted December 23, 2009 Author Share Posted December 23, 2009 If one of your cases return true, all will return true as assigning a value to a variable is always true. I think you are wanting $parameter==Value i dont understand, i thought the whole case should return true( both parameter in the case. my $parameter gets the url parameter's name so if i include this sidebar it changes according to the page type Link to comment https://forums.phpfreaks.com/topic/186175-help-with-switch-2-parameters/#findComment-983238 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 $param = 'CountryID'; // assignes CountryID to $param // will return true $param == 'CountryID'; // will check to see if the $param value is 'CountyID' // will return true if it is, or false if it isnt Link to comment https://forums.phpfreaks.com/topic/186175-help-with-switch-2-parameters/#findComment-983241 Share on other sites More sharing options...
dflow Posted December 23, 2009 Author Share Posted December 23, 2009 $param = 'CountryID'; // assignes CountryID to $param // will return true $param == 'CountryID'; // will check to see if the $param value is 'CountyID' // will return true if it is, or false if it isnt thanks Link to comment https://forums.phpfreaks.com/topic/186175-help-with-switch-2-parameters/#findComment-983260 Share on other sites More sharing options...
FaT3oYCG Posted December 23, 2009 Share Posted December 23, 2009 <?php switch ($parameter) { case ('CountryID'): if($totalRows_RsSideRatingloop > 0) { require_once('side-loop-CountryID.php'); } break; case ('CityID'): if($totalRows_RsSideRatingloop > 0) { require_once('side-loop-CityID.php'); } break; case ('RegionID'): if($totalRows_RsSideRatingloop > 0) { require_once('side-loop-RegionID.php'); } break; default: echo('empty'); } ?> and i think you will find the php operator for and is &&. you may also be able to move the $totalRows_RsSideRatingloop > 0 outside of the switch if it will be the same for all of them. Link to comment https://forums.phpfreaks.com/topic/186175-help-with-switch-2-parameters/#findComment-983262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.