if neither are met

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phplearner123
Forum Newbie
Posts: 7
Joined: Fri Apr 09, 2010 2:27 pm

if neither are met

Post by phplearner123 »

first off the dreaded noob strikes again, I am a designer moving his way into php.
I am currently working with the modx cms platform and I am creating an area for clients. when I have client A logged in it shows a custom chunk of html for them, when I have client B logged in it shows a custom chunk for them, that I have resolved, the problem I am finding is if the client is NEITHER A or B, how do I show another chunk of html?

Yes, I have gone to modx forums, but it's time I get my proverbial cr*p together and really get educated on how to properly use and implement PHP by asking the big boys. (hope you guys won't be too brutal like the Linux forums back in the day) :lol:

Code: Select all

<?php
$output ='';

$doc_id = $modx->documentIdentifier;

$doc_array_1 = array('54');
$doc_array_2 = array('107');

$username = isset($_SESSION['webShortname']) ? $_SESSION['webShortname'] : '';

if($username =='dave'){
    if(in_array($doc_id, $doc_array_1)){
        $output .='{{dave}}';
    }elseif(in_array($doc_id, $doc_array_2)){
        $output .='{{davespanish}}';
    }else{
        $output .='{{dave}}';

if($username =='bill'){
    if(in_array($doc_id, $doc_array_1)){
        $output .='{{pablo}}';
    }elseif(in_array($doc_id, $doc_array_2)){
        $output .='{{pablospanish}}';
    }else{
        $output .='{{pablo}}';

?>
the {{chunks}} shown above are custom html for those two clients in two languages, but let's say a new client logs on, i would like them to see a chunk for a new user in both languages.
any help would be enormously appreciated.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: if neither are met

Post by AbraCadaver »

This looks like it will become unwieldy fairly quickly unless those are the only two users that you'll ever do this for. But to answer your question, based on your current code you could add this at the end:

Code: Select all

if(empty($output)) {
    //do whatever
}
Or you could convert this into a switch statement:

Code: Select all

switch($username){

    case 'dave':
       if(in_array($doc_id, $doc_array_1)){
           $output .='{{dave}}';
       }elseif(in_array($doc_id, $doc_array_2)){
           $output .='{{davespanish}}';
       }else{
           $output .='{{dave}}';
       }
       break;

    case 'bill':
       if(in_array($doc_id, $doc_array_1)){
           $output .='{{pablo}}';
       }elseif(in_array($doc_id, $doc_array_2)){
           $output .='{{pablospanish}}';
       }else{
           $output .='{{pablo}}';
       }
       break;

    default:
       //do something
       break;
}
Last edited by AbraCadaver on Fri Apr 09, 2010 3:17 pm, edited 3 times in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: if neither are met

Post by AbraCadaver »

Added a switch.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
phplearner123
Forum Newbie
Posts: 7
Joined: Fri Apr 09, 2010 2:27 pm

Re: if neither are met

Post by phplearner123 »

thanks for the super fast reply AbraCadaver !!

the first code didn't work and inserted this into the default area of your switch suggestion

Code: Select all

     if(in_array($doc_id, $doc_array_1)){
        $output .='{{newclient}}';
    }elseif(in_array($doc_id, $doc_array_2)){
        $output .='{{newclientspanish}}';
    }else{
        $output .='{{newclient}}';
but I couldn't get an output.

I know about it become a hassle as more client join, but I am nowhere near the level of hacking my login php to create a chunk of html and inserted in the appropriate place yet, I am a few years away to say the least, but maybe as my company get's bigger I can go back to designing, photography and messing with autodesk only and hire a PHP and JavaScript guru. Right now the way I have the custom html chunks laid out, its a fifteen minute operation of personalizing links to my site's sandbox, so I am hoping I won't be pulling my hair out with it (fingers crossed)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: if neither are met

Post by AbraCadaver »

Show all the new code with the switch.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
phplearner123
Forum Newbie
Posts: 7
Joined: Fri Apr 09, 2010 2:27 pm

Re: if neither are met

Post by phplearner123 »

here it is:

Code: Select all

<?php
$output ='';

$doc_id = $modx->documentIdentifier;

$doc_array_1 = array('54');
$doc_array_2 = array('107');

$username = isset($_SESSION['webShortname']) ? $_SESSION['webShortname'] : '';

switch($username){
    case 'dave':
    if(in_array($doc_id, $doc_array_1)){
        $output .='{{dave}}';
    }elseif(in_array($doc_id, $doc_array_2)){
        $output .='{{davespanish}}';
    }else{
        $output .='{{dave}}';
    break;

    case 'bill':
    if(in_array($doc_id, $doc_array_1)){
        $output .='{{bill}}';
    }elseif(in_array($doc_id, $doc_array_2)){
        $output .='{{billspanish}}';
    }else{
        $output .='{{bill}}';
    break;

    default:
        if(in_array($doc_id, $doc_array_1)){
        $output .='{{newclient}}';
    }elseif(in_array($doc_id, $doc_array_2)){
        $output .='{{newclientspanish}}';
    }else{
        $output .='{{newclient}}';
    break;
}
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: if neither are met

Post by AbraCadaver »

You're missing the closing } after your three else statements.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
phplearner123
Forum Newbie
Posts: 7
Joined: Fri Apr 09, 2010 2:27 pm

Re: if neither are met

Post by phplearner123 »

that did the trick! told you I was a one of "those" noobs, but a closing a statement? that's pretty bad...thanks guys, but you may be too good for your own good, cause now I will be back! :lol: :lol:

all kidding aside, I really appreciate communities that really take the time to help and empower people! thank you so much!
Post Reply