Does PHP have an end-of-file problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Webb

    Does PHP have an end-of-file problem.

    Am just starting to learn PHP so I really don't know my way around but
    my first script works fine except for one problem. Within the script is
    a sql query that selects * from mytable. The result is that all my
    records are shown except the first record in the table which is stripped
    from the results. If I modify the query to select the name of the
    person who is shown in the first record I get zero results. A direct
    MYSQL query produces the desired result.

    My uneducated opinion is that there is an e.o.f. problem somewhere!

    Any help will be appreciated.

    GW.
  • adlerweb

    #2
    Re: Does PHP have an end-of-file problem.

    George Webb schrieb:
    Within the script is
    a sql query that selects * from mytable. The result is that all my
    records are shown except the first record in the table which is stripped
    from the results. If I modify the query to select the name of the
    person who is shown in the first record I get zero results. A direct
    MYSQL query produces the desired result.
    No, there should be no problem with PHP. You have not provided your code
    so i cant say whats wrong. Review your code and read the manual.

    Florian

    Comment

    • no@email.com

      #3
      Re: Does PHP have an end-of-file problem.

      assuming you fetch database data as array,
      your script should fetch array starting from 0, not 1.

      but, to be 100% sure, please post your code here.

      Comment

      • George Webb

        #4
        Re: Does PHP have an end-of-file problem.

        adlerweb wrote:
        George Webb schrieb:
        >Within the script is
        >a sql query that selects * from mytable. The result is that all my
        >records are shown except the first record in the table which is stripped
        >from the results. If I modify the query to select the name of the
        >person who is shown in the first record I get zero results. A direct
        >MYSQL query produces the desired result.
        >
        No, there should be no problem with PHP. You have not provided your code
        so i cant say whats wrong. Review your code and read the manual.
        >
        Florian
        Thanks. Here is the script in question:
        <?php
        $host= "host";
        $user= "user";
        $password= "";
        $database = "mydb";


        $mysql = mysql_connect($ host, $user, $password);

        if (!$mysql=mysql_ connect($host, $user, $password)) {
        printf("Connect failed: %s\n", mysql_connect_e rror());
        exit();

        mysql_close($my sql);
        }
        // Select Database

        $db=mysql_selec t_db('mydb',$my sql)
        or die ("Couldn't select database.");
        // Get Data
        $name = "My Table";

        $query= "SELECT * FROM members ORDER BY lname";
        $result = mysql_query($qu ery)
        or die ("Couldn't execute query.");

        $row = mysql_fetch_arr ay($result);
        $name = ucfirst($name);

        //Display results in a table

        echo "<h1>$name</h1>";
        echo "<table cellspacing = '15'>";
        echo "<tr><td colspan = '5'><hr></td></tr>";
        while ($row =mysql_fetch_ar ray($result))

        {


        extract($row);

        echo "<tr>\n
        <td>$id</td>\n
        <td>$fname</td>\n
        <td>$lname</td>\n
        <td>$address</td>\n
        <td>$phone</td>\n
        <td>$email</td>\n
        </tr>\n";
        echo "<tr><td colspan='5'><hr ></td></tr>\n";
        }
        echo "</table>\n";

        Comment

        • George Webb

          #5
          Re: Does PHP have an end-of-file problem.

          no@email.com wrote:
          assuming you fetch database data as array,
          your script should fetch array starting from 0, not 1.
          >
          but, to be 100% sure, please post your code here.
          Script posted on my message timed at 8:54 am. Thanks.

          GW

          Comment

          • no@email.com

            #6
            Re: Does PHP have an end-of-file problem.

            you have fetched result twice.
            that's why your first line is hidden.
            it's taken out by the first $row;

            fine and comment this line

            #$row = mysql_fetch_arr ay($result);
            $name = ucfirst($name);

            Comment

            • George Webb

              #7
              Re: Does PHP have an end-of-file problem.

              no@email.com wrote:
              you have fetched result twice.
              that's why your first line is hidden.
              it's taken out by the first $row;
              >
              fine and comment this line
              >
              #$row = mysql_fetch_arr ay($result);
              $name = ucfirst($name);
              You're a genius! Your help fixed it. Many thanks.

              GW

              Comment

              • Curtis

                #8
                Re: Does PHP have an end-of-file problem.

                Just curious, but George, have you programmed in C or C++ before?

                For what it's worth, here are some things you can do to increase
                performance a bit. In PHP, strings do not need to have double quotes
                unless they contain variables or whitespace metacharacters like \t, \n,
                \r, etc. If you switch to single quotes, the PHP interpreter won't
                execute variable interpolation on strings on which it's not needed.
                >if (!$mysql=mysql_ connect($host, $user, $password)) {
                printf("Connect failed: %s\n", mysql_connect_e rror());
                exit();
                >
                mysql_close($my sql);
                >}
                Not related to performance, but after exit() is called, nothing is
                executed, so there's no need to close the connection, unless you do it
                before. At the very least, you'll get rid of a couple extra lines :P

                You also call mysql_fetch_arr ay, which generates two arrays, one
                indexed, and one associative array (hash, dictionary, etc.). If you
                call mysql_fetch_ass oc() instead, you'll also save some time.

                I guess this wouldn't affect you too much, unless you had an enormous
                amount of data to sort through.

                Curtis

                Comment

                • George Webb

                  #9
                  Re: Does PHP have an end-of-file problem.

                  Curtis, no I'm not a programmer, just someone trying to put a database
                  on my web site. I do however appreciate your input and will amend my
                  script accordingly. Many thanks.

                  GW.

                  Curtis wrote:
                  Just curious, but George, have you programmed in C or C++ before?
                  >
                  For what it's worth, here are some things you can do to increase
                  performance a bit. In PHP, strings do not need to have double quotes
                  unless they contain variables or whitespace metacharacters like \t, \n,
                  \r, etc. If you switch to single quotes, the PHP interpreter won't
                  execute variable interpolation on strings on which it's not needed.
                  >
                  >if (!$mysql=mysql_ connect($host, $user, $password)) {
                  > printf("Connect failed: %s\n", mysql_connect_e rror());
                  > exit();
                  >>
                  > mysql_close($my sql);
                  >}
                  Not related to performance, but after exit() is called, nothing is
                  executed, so there's no need to close the connection, unless you do it
                  before. At the very least, you'll get rid of a couple extra lines :P
                  >
                  You also call mysql_fetch_arr ay, which generates two arrays, one
                  indexed, and one associative array (hash, dictionary, etc.). If you
                  call mysql_fetch_ass oc() instead, you'll also save some time.
                  >
                  I guess this wouldn't affect you too much, unless you had an enormous
                  amount of data to sort through.
                  >
                  Curtis
                  >

                  Comment

                  • Curtis

                    #10
                    Re: Does PHP have an end-of-file problem.

                    Your coding style reminded me of C for some reason (nothing wrong with
                    that, just an observation).

                    Good luck with your site,
                    Curtis

                    On Dec 29, 3:49 pm, George Webb <nom...@msn.com wrote:
                    Curtis, no I'm not a programmer, just someone trying to put a database
                    on my web site. I do however appreciate your input and will amend my
                    script accordingly. Many thanks.
                    >
                    GW.
                    >
                    Curtis wrote:
                    Just curious, but George, have you programmed in C or C++ before?
                    >
                    For what it's worth, here are some things you can do to increase
                    performance a bit. In PHP, strings do not need to have double quotes
                    unless they contain variables or whitespace metacharacters like \t, \n,
                    \r, etc. If you switch to single quotes, the PHP interpreter won't
                    execute variable interpolation on strings on which it's not needed.
                    >
                    if (!$mysql=mysql_ connect($host, $user, $password)) {
                    printf("Connect failed: %s\n", mysql_connect_e rror());
                    exit();
                    >
                    mysql_close($my sql);
                    }
                    Not related to performance, but after exit() is called, nothing is
                    executed, so there's no need to close the connection, unless you do it
                    before. At the very least, you'll get rid of a couple extra lines :P
                    >
                    You also call mysql_fetch_arr ay, which generates two arrays, one
                    indexed, and one associative array (hash, dictionary, etc.). If you
                    call mysql_fetch_ass oc() instead, you'll also save some time.
                    >
                    I guess this wouldn't affect you too much, unless you had an enormous
                    amount of data to sort through.
                    >
                    Curtis

                    Comment

                    Working...