Jump to content

help with switch 2 parameters


dflow

Recommended Posts

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

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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.