Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3

Thread: Select question

  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Im developing an app in .NET and wish to know how many records are in a table

    Code:
    select count(*) FROM tablename
    Two questions..
    1: is count the column name or should I replace the asterix with the column name?

    And 2: How do I put that value into a variable? Is it like..

    Code:
    select set variable_name to count(*) from tablename
    Thanks for help guys

  2.  

  3. #2
    Senior Member ericbusch's Avatar
    Join Date
    Aug 2003
    Location
    Daejeon, South Korea
    Posts
    241
    Member #
    2779
    PHP Code:
    $sql "SELECT COUNT(*) AS num_rows FROM tablename";
    $result mysql_query($sql);
    $row mysql_fetch_array($result);
    echo 
    $row['num_rows']; 
    you can echo the number of results with
    PHP Code:
    echo $row['num_rows']; 
    or you can set that equal to any variable that you choose like
    PHP Code:
    $total_num_rows $row['num_rows']; 
    hope this helps

    eric
    Blogs For Sale - Each blog is packed with 1000s of signatures and ads are highly integrated into the site. Great CTR! Completely customizable from Admin CP. On Sale!
    Complete Websites For Sale - Fantastic looking sites rich with content. Come complete with domain names. I only have a couple of these.

  4. #3
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    A script generated query, normally returns a resource identifier, and cannot be used to set a script variable directly.

    As Eric showed in his example, you have to use other language features to extract the resultset.

    ---------

    With regard to the count(*) feature, that's fairly well explained here(with multiple examples and an exercise):
    http://www.webdevelopersnotes.com/tu..._counting.php3

    As to setting variables directly, you can read the below excerpt from the manual. However, the SET variables are usually used in further DB queries directly, not to be returned to scripts as resultsets.
    http://sunsite.mff.cuni.cz/MIRRORS/f...ET_OPTION.html
    S. Rosland


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com