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
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";
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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.