Jump to content

[SOLVED] Switch - Cases (HELP!)


unsider

Recommended Posts

Can I use a switch case to do this sort of thing. I am really having trouble rationalizing this, because i've only done static switch cases.

Take a look at the code, and hopefully it will make sense.

index.php?aid=52&cid=1

 

dynamic switch cases?

 

functions?

 

// code used to determine the articleid + category

$row_articles['artid']&cid=$row_articles['categoryID']

 

if(isset($_GET['aid'])){
$aid=$_GET['aid'];
switch($aid)
{

    Case "$row_articles['artid']&cid=$row_articles['categoryID']";
break;
    Default;     
        break;
           }
}else{

echo 'Whatever';

}

 

Thanks, if you need more code, explanation, I'll do my best to provide, don't be shy in asking.

Link to comment
https://forums.phpfreaks.com/topic/112869-solved-switch-cases-help/
Share on other sites

$_GET['aid'] will never evaluate to $row_articles['artid']&cid=$row_articles['categoryID'], look at it.

 

But yes, to answer your question. Cases can easily come from a dynamic source. eg;

 

$cases = array('foo','bar','bob');

switch ('bob') {
  case: $cases[0];
    echo "Found {$cases[0]}";
    break;
  case: $cases[1];
    echo "Found {$cases[1]}";
    break;
  case: $cases[2];
    echo "Found {$cases[2]}";
    break;
  default:
    echo "Case not found";
}

I'm trying to 'evaluate to' $row_articles['artid']&cid=$row_articles['categoryID']

 

Retrieve the aid, and catid and create a switch case.

 

Really just implementing this into a switchcase.

 

I'm not sure how to go about doing this, would I use the model you've provided, or was that an obscure example?

I'm sorry but your obscure examples do not help descibe what it is exactly your trying to do. I'll have a guess, based on this url...

 

index.php?aid=52&cid=1

 

and bits of your original post.

 

if (isset($_GET['aid'] && isset($_GET['cid'])) {
  $check = $_GET['aid'] . '&cid=' . $_GET['cid'];
  switch ($check) {
    case "{$row_articles['artid']}&cid={$row_articles['categoryID']}":
      echo "found";
      break;
  }
}

 

Still I fail to see the point.

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.