Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Flat file array, replace 3rd key value based on itself.

    Good day to all of you,
    Him working of a login script and him stopped at the display of the member.
    The script is easy and it's text(flat) file based.
    My problem is at the 3rd array level, when I try to display it, I need to change the value based on what it is.


    here's the code :

    PHP Code:


     <?PHP
    $file 
    file("pass.txt');
    $data= array();

        
    $director = "
    Director/index.php";
    $pretty = "
    Pretty/index.php";
    $users = "
    User/index.php";



    foreach($file as $value){
        list($user, $password, $url) = explode('=>', $value);
        $data[$user] = array("
    url"=>$url, "password"=>$password);
        
        

    if ($url==$director):
    echo "
    <b>Member : </b>". $user ."<br/>";
    echo "
    <b>Code : </b>". $password ."<br/>";
    echo "
    <b>Status : </b>Director<br/><br/>";

    else if ($url==$pretty) :
    echo "
    <b>Member : </b>". $user ."<br/>";
    echo "
    <b>Code : </b>". $password ."<br/>";
    echo "
    <b>Status : </b>Pretty<br/><br/>";

    else:
    echo "
    <b>Member : </b>". $user ."<br/>";
    echo "
    <b>Code : </b>". $password ."<br/>";
    echo "
    <b>Status : </b>User<br/><br/>";

    endif;


    }

    ?>

    Thanks !
    Take care !
    Last edited by Peuplarchie; 07-21-2008 at 04:51 AM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Is that your exact code?

    Are you getting any errors?

    You should be getting a parse error on the first line. You are missing a quote.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Peuplarchie (07-22-2008)

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Yes it is, my exact code, The quote is corrected, and it is not the problem here, I'm getting an :

    Parse error: syntax error, unexpected T_IF, expecting ':' in

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You aren't using the correct if else syntax. I'm not sure why you thought a : represented an opening if statement or an endif; ended it.
    PHP Code:
    <?php
    $file 
    file("pass.txt")
    $data= array();

        
    $director "Director/index.php";
    $pretty "Pretty/index.php";
    $users "User/index.php";



    foreach(
    $file as $value){
        list(
    $user$password$url) = explode('=>'$value);
        
    $data[$user] = array("url"=>$url"password"=>$password);
        
        

    if (
    $url==$director) {
    echo 
    "<b>Member : </b>$user<br/>";
    echo 
    "<b>Code : </b>$password<br/>";
    echo 
    "<b>Status : </b>Director<br/><br/>";
    }
    else if (
    $url==$pretty) {
    echo 
    "<b>Member : </b>$user<br/>";
    echo 
    "<b>Code : </b>$password<br/>";
    echo 
    "<b>Status : </b>Pretty<br/><br/>";
    }
    else {
    echo 
    "<b>Member : </b>$user<br/>";
    echo 
    "<b>Code : </b>$password <br/>";
    echo 
    "<b>Status : </b>User<br/><br/>";
    }
    }
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Peuplarchie (07-22-2008)

  • #5
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Colons are valid syntax, see here.

    However, Peuplarchie missed this paragraph:
    Quote Originally Posted by http://www.php.net/manual/en/control-structures.elseif.php
    Note: Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • Users who have thanked dumpfi for this post:

    Peuplarchie (07-22-2008)

  • #6
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    it is not giving me error now, but it change the value of the url for all and put user like so :



    Member : Jack
    Code : Daniel
    Status : User

    Member : Angolina
    Code : Joli
    Status : User

    Member : Mike
    Code : Lee
    Status : User

  • #7
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    PHP Code:

     <?PHP
    $file 
    file("../../info.txt");
    $data= array();

        
    $director "Director/index.php";
    $pretty "Pretty/index.php";
    $users "User/index.php";



    foreach(
    $file as $value){
        list(
    $user$password$url) = explode('=>'$value);
        
    $data[$user] = array("url"=>$url"password"=>$password);
        
    if (
    $url==$director):
    echo 
    "<b>Member : </b>"$user ."<br/>";
    echo 
    "<b>Code : </b>"$password ."<br/>";
    echo 
    "<b>Status : </b>Director<br/><br/>";


    elseif (
    $url==$pretty):
    echo 
    "<b>Member : </b>"$user ."<br/>";
    echo 
    "<b>Code : </b>"$password ."<br/>";
    echo 
    "<b>Status : </b>Pretty<br/><br/>";

    else:
    echo 
    "<b>Member : </b>"$user ."<br/>";
    echo 
    "<b>Code : </b>"$password ."<br/>";
    echo 
    "<b>Status : </b>User<br/><br/>";

    endif;
    }
    print_r ($data)

    ?>

  • #8
    Regular Coder
    Join Date
    Mar 2008
    Posts
    103
    Thanks
    1
    Thanked 8 Times in 8 Posts
    I would recommend you use { } instead of if endif. but thats just my opinion...But in either case make sure you have elseif as one word .

  • Users who have thanked p4plus2 for this post:

    Peuplarchie (07-22-2008)

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by dumpfi View Post
    Colons are valid syntax, see here.

    However, Peuplarchie missed this paragraph:
    dumpfi
    My mistake. I've never used that syntax so didn't know it was valid. Apologies to the OP.

    Start echoing out the $url value to see what you are getting. It seems like its getting to the last else statement.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Peuplarchie (07-22-2008)

  • #10
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    it's the same, I just can't figure why it don't work.
    Exact, it jum,ps the 2 first and go to the last one.

  • #11
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    erm... this may sound stupid, but have you ever tried checking your paths?

    $director = "Director/index.php";
    $pretty = "Pretty/index.php";
    $users = "User/index.php";

    if the paths are actually all in lower, then its gonna fail, thats if its a linux box.

    It is usually overlooked alot by people.

    oh and another thing, that last lot of code you posted will fail with missing ";"

    print_r($data)
    should be:
    print_r(data);

  • Users who have thanked scoop_987 for this post:

    Peuplarchie (07-22-2008)

  • #12
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    RESOLVED

    PHP Code:
    foreach($file as $value){ 
        
    $value trim($value);
        list(
    $user$password$url) = explode('=>'$value); 
        
    $data[$user] = array("url"=>$url"password"=>$password); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •