Jump to content

eawf

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Posts posted by eawf

  1. Hi,

    I have a text file such as:

    Tab1a||Tab2a||Tab3a
    Tab1b||Tab2b||Tab3b

     

    Now when i display this data, i want to display the line number next to it (i.e. Tab1b... line 2)

    How would i do that?

    Thanks

     

    One way would be:

     

    $rows = @file("/path/to/filename.ext");
    foreach($rows as $key=>$value){
    $row = $key+1;
    echo $value." line ".$row."<br />";
    }
    

  2. Am I correct?

     

    No.

     

    The issue is that this (psuedo) code doesn't work:

     

    $rows[ ] = "eawf:otherstuff\n";
    $testdata = "eawf";
    foreach($rows as $row){
    $data = explode(":",$row);
    if($data[0] == $testdata){
      header("Location: $self");
    }
    }
    

     

    while this one does work:

     

    $rows[ ] = "eawf:otherstuff\n";
    $testdata = "eawf";
    foreach($rows as $row){
    $data = explode(":",$row);
    if($data[0] == $testdata){
      $flag = true
    }
    }
    if(isset($flag)){
      header("Location: $self");
    }
    

     

    actually does work.  So the question is, WHY doesn't the first code snippet work?

     

    The psuedo code for the above is:

     

    Form submit provides input vars for userid and password.
    read all records from .htpasswd and load to an array ($rows)
    process array one element at a time
    parse array vars via ":" character.
    if userid from form matches the userid from .htpassword:
      reload the page with a get var loaded with an error message.
    else process next record.
    

     

    I can[t find anything online indicating that the foreach loop is not able to be broken by issuing the header() function, which, at least to my way of thinking, should stop program code execution by simply reloading the page again.  What ends up happening is that the program continues to run and the header statement is not executed.

     

    Hope this makes sense?

     

     

  3. You're not returning a true/false statement in your second code.

     

    Am I missing something.  The if statement is exactly the same.  Shouldn't the condition being true kick in the header statement which would reload the page with the error message passed in the get?

     

     

    Also, you're using a header to redirect, which only works if the browser hasn't received data yet (if the header has been established).

     

     

    Yeah, I checked that previously to verify that headers weren't being sent, and they're not, PLUS that doesn't explain why the header statement works below the foreach loop, right?

     

    I till try again with the settings turned on to see if there's something generated.

  4. I have an administrative back end on a secure server that I want to use Basic Authentication for.

     

    In my "Add" module, I can't figure out why this works:

    
    $rows = file($passfile);
    import_request_variables("gp","x_");
    
    switch($x_action){
      case "Add":
    
    ...
    
       foreach($rows as $row){
        $data = explode(":",$row);
        if($x_userid == $data[0]){
         $dupe = 1;
         $errormsg = "Duplicate Record!";
        }
       }
    
    ...
    
       if($dupe == 0){
        write_rows($passfile,$rows);
        header("Location: $self");
       }else{
        header("Location: $self?errormsg=$errormsg");
       }
      break;
    
    ...
    
    

     

    and this doesn't:

     

    
    $rows = file($passfile);
    import_request_variables("gp","x_");
    
    switch($x_action){
      case "Add":
    
    ...
    
       foreach($rows as $row){
        $data = explode(":",$row);
        if($x_userid == $data[0]){
         header("Location: $self?errormsg=Duplicate Record!");
        }
       }
    
    ...
      break;
    

     

    Thanks in advance for your constructive comments.

  5. Check your Error Logs for the actual PHP error.

    Also, instead of writing the connect code, use Justin Vincent's ez_SQL database wrapper. Makes database interactions rediculously simple.

    [!--quoteo(post=382122:date=Jun 10 2006, 01:30 AM:name=PC-SandMan^^)--][div class=\'quotetop\']QUOTE(PC-SandMan^^ @ Jun 10 2006, 01:30 AM) [snapback]382122[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Hi
    I've installed Postgre for first time and tried to connect php

    <?php
    echo "1";
    pg_connect("host=localhost ...");
    echo "2";
    ?>

    I was expecting an error on the connection string maybe
    but all I got was

    1

    ... I tried several times with different connection strings ... and aways
    php stoped on pg_connect

    help ?

    thx
    [/quote]
×
×
  • 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.