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

Link to comment
Share on other sites

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