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
  1. #1
    Junior Member
    Join Date
    Mar 2006
    Location
    United Kingdom
    Posts
    2
    Member #
    12863
    I'm new to PHP and was wondering if someone could help me create a simple count function. I have a table consisting of two columns, player and manager. I want to count the number of players that belong to a specific manager and, depending upon the result, return a value of either true or false. It should go something like:

    SELECT player FROM [table] WHERE manager=[condition]
    IF number of players <= 20
    PRINT true
    ELSE
    PRINT false


    Any help would be much appreciated. Also, could anybody recommend a free (or cheap!) web host for a database-driven site? Thanks.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey. Welcome to WDF

    For your code query, here you go.

    PHP Code:
    <?php

    // database connection code here
    // or include a connection file

    // i will assume you have connected by now
    $mgr // ? im presuming it will be an integer value, if its a string/varchar then put
    // single quotes around it
    $select_res mysql_query("SELECT COUNT(*) FROM table WHERE manager = $mgr") or die(mysql_error());
    $num mysql_result($select_res0);
    if(
    $num <= 20)
      {
        echo 
    "True";
      }
    else
      {
        echo 
    "False";
      }

    mysql_close();
    ?>
    I hope that it easy enough to understand, $num will hold the number of rows returned which match the condition.

    There are most likely free ones, but I pay 35 and get a years hosting plus a .co.uk domain for 2 years at ukwsd.co.uk

    Also, what do you mean by database-driven, as in, with ASP/PHP etc?

  4. #3
    Junior Member
    Join Date
    Mar 2006
    Location
    United Kingdom
    Posts
    2
    Member #
    12863
    Thanks, that's perfect. Yeah, I just meant PHP; I'll check out ukwsd.co.uk. Much appreciated. :classic:


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:34 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com