Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-16-2009, 01:16 PM Looping in a switch
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
PHP Code:
    $query_links "select link_name, link_page from admin_links";
    
$mysql_links mysql_query($query_links) or die(mysql_error());
    switch(
$page) {
        while (
$fetch_links mysql_fetch_array($mysql_links)) {
            case 
"$fetch_links[\"link_name]\"]":
                require_once(
"$fetch_links[\"link_page\"]");
                break;
        }
    } 
Basically I had this idea this morning. So I thought I would give it a shot.

And it doesn't seem to run(big surprise) the switch doesn't like the loop inside of it.

Any thoughts of how to get this to work though?
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
 
Register now for full access!
Old 06-16-2009, 01:31 PM Re: Looping in a switch
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Is this what you were going for?

PHP Code:
    $query_links "select link_name, link_page from admin_links";
    
$mysql_links mysql_query($query_links) or die(mysql_error());
    while (
$fetch_links mysql_fetch_array($mysql_links)) 
    {
        switch(
$page)
        {
            case 
"$fetch_links[\"link_name]\"]":
                require_once(
"$fetch_links[\"link_page\"]");
                break;
        }
    } 
A switch statement must be of the form:

Code:
switch(subject)
{
     case 1:
          //code here
     case 2:
          //code here
     .
     .
     .
     case n:
          //code here
}
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-16-2009, 01:41 PM Re: Looping in a switch
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Is this what you were going for?

PHP Code:
    $query_links "select link_name, link_page from admin_links";
    
$mysql_links mysql_query($query_links) or die(mysql_error());
    while (
$fetch_links mysql_fetch_array($mysql_links)) 
    {
        switch(
$page)
        {
            case 
"$fetch_links[\"link_name]\"]":
                require_once(
"$fetch_links[\"link_page\"]");
                break;
        }
    } 
A switch statement must be of the form:

Code:
switch(subject)
{
     case 1:
          //code here
     case 2:
          //code here
     .
     .
     .
     case n:
          //code here
}
Yea I know.

I was just curious if there is a way to do something like I am trying.
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
Old 06-16-2009, 03:37 PM Re: Looping in a switch
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
How is what you are trying to do different from the code I posted? I'm not sure what you are going for.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 06-16-2009 at 11:54 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-16-2009, 11:19 PM Re: Looping in a switch
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Is this what you were going for?
PHP Code:
    $query_links "select link_name, link_page from admin_links";
    
$mysql_links mysql_query($query_links) or die(mysql_error());
    while (
$fetch_links mysql_fetch_array($mysql_links)) 
    {
        switch(
$page)
        {
            case 
"$fetch_links[\"link_name]\"]":
                require_once(
"$fetch_links[\"link_page\"]");
                break;
        }
    } 
In which case you'd be better off with a simple IF.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-19-2009, 03:07 AM Re: Looping in a switch
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
That's some crazy logic if i ever saw it. You would have to change the value of the switch($page) variable and I don't see how that would happen in any of yer'all's examples.
jason_alan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Looping in a switch
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23362 seconds with 12 queries