unsider Posted July 2, 2008 Share Posted July 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 $_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"; } Quote Link to comment Share on other sites More sharing options...
unsider Posted July 2, 2008 Author Share Posted July 2, 2008 Still trying to figure it out, but anyone wanna help me implement this, or atleast nudge me in the right direction? Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 Where exactly are you stuck? Quote Link to comment Share on other sites More sharing options...
unsider Posted July 2, 2008 Author Share Posted July 2, 2008 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? Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
unsider Posted July 2, 2008 Author Share Posted July 2, 2008 after you posted that, i looked at my code and saw a method that would work for me, your example was close enough for me to figure it out. Thank you very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.