Database rows count into HTML webpage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mlfilms
    New Member
    • Apr 2007
    • 6

    Database rows count into HTML webpage

    Hi,
    I'm trying to get the number of rows from a specific database table to appear as text in an HTML webpage.
    Here's the code I have, but can't figure out what's wrong and why it won't display. I have it in the middle of a form.
    Any help would be appreciated.


    <html>
    <body>
    <?php
    $connection = mysql_connect(" localhost", "XUSERX", "XPASSX");
    mysql_select_db ("XDATABASENAME X", $connection);
    $result = mysql_query("SE LECT * FROM xdatabasetablex ;);
    {
    echo $result. "of 200 needed".;
    }
    ?>
    </body>
    </html>
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Code:
    $result = mysql_query("SELECT * FROM xdatabasetablex
    This returns a resource result not an integer. You need [PHP]mysql_num_row($ result)[/PHP]

    Comment

    • mlfilms
      New Member
      • Apr 2007
      • 6

      #3
      OK, so this is the script then?

      <html>
      <body>
      <?php
      $connection = mysql_connect(" localhost", "XUSERX", "XPASSX");
      mysql_select_db ("XDATABASENAME X", $connection);
      mysql_num_row($ result);
      {
      echo $result. "of 200 needed".;
      }
      ?>
      </body>
      </html>


      It doesn't show the number of rows.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        No this is the script
        [PHP]html>
        <body>
        <?php
        $connection = mysql_connect(" localhost", "XUSERX", "XPASSX");
        mysql_select_db ("XDATABASENAME X", $connection);
        $result = mysql_query("SE LECT * FROM xdatabasetablex ");
        echo mysql_num_rows( $result). "of 200 needed".;
        ?>
        </body>
        </html>[/PHP]

        Comment

        • mlfilms
          New Member
          • Apr 2007
          • 6

          #5
          Thanks. I cannot seem to get this working though. Nothing is showing up

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            Code:
            SELECT * FROM xdatabasetablex
            In that case your select statement has returned an empty recordset

            Comment

            • mlfilms
              New Member
              • Apr 2007
              • 6

              #7
              There are 19 rows in the database as of today. the database name is tinasti_frgn1 and the table is recipeinfo. I have all that info in the code and the username password, etc.
              I'm not sure what I'm doing wrong.

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                Then get some debugging in and have a look!
                [PHP]<html>
                <body>
                <?php
                $connection = mysql_connect(" localhost", "XUSERX", "XPASSX");
                mysql_select_db ("XDATABASENAME X", $connection)
                or die('Failed - Error no '.mysql_errorno ().' Message '.mysql_error() )
                $result = mysql_query("SE LECT * FROM xdatabasetablex ")
                or die('Failed - Error no '.mysql_errorno ().' Message '.mysql_error() )
                echo mysql_num_rows( $result).' of 200 needed';
                ?>
                </body>
                </html>[/PHP]
                When compiling code, continually echo out variables, recordsets and messages otherwise you won't have a clue what is happening.

                Comment

                • mlfilms
                  New Member
                  • Apr 2007
                  • 6

                  #9
                  Still nothing.
                  I tried it on a blank page and nothing. It's quite puzzling.

                  Comment

                  • code green
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 1726

                    #10
                    tried it on a blank page and nothing. It's quite puzzling
                    Can you echo ANYTHING out on to the page?

                    Comment

                    • mlfilms
                      New Member
                      • Apr 2007
                      • 6

                      #11
                      Nothing at all.

                      Comment

                      • code green
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1726

                        #12
                        Well your page is wrong. I suspect you have error reporting turned off. Use this line before connecting to the DB [PHP]error_reporting (E_ALL | E_STRICT);[/PHP]This will switch on error reporting for the duration of the script. Also try and echo something out. Change the entry point of your script to [PHP]<html><body>Hel lo there<?php echo 'Hello Again';[/PHP]But if your script is not compiling you wil not get this far

                        Comment

                        Working...