SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Texas
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Why is it always '1' ?

    I'm a newbie at this, this is my first project. I got about a half dozen static pages built with xhtml 1.0 and everything links fine. Then I wanted to add the database to control the page content. I have two mysql queries that always return the value '1'.

    1) The first happens after a successful connect, here is the code snippet:

    $DbList = mysql_list_dbs ($conn);
    $ListSz = mysql_num_fields ($DbList);
    echo "MysqlConnect: DBCount = " . $ListSz . ", ";

    Before I created my database, the value was '1'. After the database was successfully created, the value is still '1'.

    2) The second happens when I try to create tables, here is the code snippet:

    $txt = "SHOW TABLES";
    $TbList = mysql_query ($txt);
    $ListSz = mysql_num_fields ($TbList);
    echo "MysqlConnect: TableCount = " . $ListSz . ", ";

    Before I created a single table, I got a result of '1'. I successfully created 2 tables and I still get the value of '1'.

    For my environment I'm using the latest version of MAMP (1.7.2 I believe).

    I'm hoping someone can tell me what I'm doing wrong?

    awolbush

  2. #2
    SitePoint Zealot Steveiwonder's Avatar
    Join Date
    Nov 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    Code PHP:
    instead of
    Code PHP:

    This is more of a PHP question ^^

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,048
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    show tables; - results in one column. The column contains the names of the tables. If you run that SQL inside the terminal you'll see what I mean. As suggested mysql_num_rows is what your after.

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Welcome to the forums, AwolBush.

    MySQL_Num_Fields()' job is to tell you how many fields are returned by the query.

    MySQL_Num_Rows()' job is to tell you how many rows are returned.

    For example:
    PHP Code:
    <?php
    $Query 
    MySQL_Query('SELECT ID, Name, Value FROM Table LIMIT 10');
    $RowCount MySQL_Num_Rows($Query); // 10 rows, as given by the limit.
    $FieldCount MySQL_Num_Fields($Query); // 3 fields - ID, Name, Value.
    The MySQL_List_DBs() function returns how many databases are available in the connection. Only one field is in that result, 'Database'.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Texas
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, the mysql_num_rows () gave the expected results.

    awolbush

    If my IQ was 1 point lower I couldn't fly this frakkin' jet.


Bookmarks

Posting Permissions

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