[PHP] Total Accounts & Characters

Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Member mutter is offline
    MemberRank
    Dec 2010 Join Date
    ArgentinaLocation
    64Posts

    Re: [PHP] Total Accounts & Characters

    Quote Originally Posted by BGRick View Post
    PHP Code:
    Parse errorsyntax errorunexpected T_CONSTANT_ENCAPSED_STRINGexpecting ',' or ';' in C:\Program Files\XAMMP\xampplite\htdocs\source\regusers.php on line 6 


    ---------- Post added at 05:34 PM ---------- Previous post was at 05:33 PM ----------



    PHP Code:
    Fatal errorCall to undefined function mssql_connect() in C:\Program Files\XAMMP\xampplite\htdocs\source\regusers.php on line 8 
    echo "Total Accounts: ".$execquery " - ";
    change to echo "Total Accounts: ".$execquery." - ";

  2. #17
    Account Upgraded | Title Enabled! BGRick is offline
    MemberRank
    Oct 2010 Join Date
    The NetherlandsLocation
    437Posts

    Re: [PHP] Total Accounts & Characters

    Quote Originally Posted by alfredao View Post
    Here has my function. It's easy to use.

    PHP Code:
    function total($tabela$cond null)
    {
            
         
    $query "SELECT COUNT(*) AS total FROM " $tabela . (($cond != null) ? " " $cond "");
         
    $sql   mssql_query($query);
         
    $c     mssql_fetch_array($sql);
         return 
    $c['total'];

    Usage:

    PHP Code:
    echo total("Accounts"); //Print in screen the total of Accounts 
    PHP Code:
    echo total("Accounts""WHERE UGradeID = 253"); //Print in screen the total of banneds Accounts 
    So, if you want the total of active characters.

    PHP Code:
    echo total("Character""WHERE DeleteName IS NULL"); //Print in screen the total of active Characters 
    I don't get this one o.o

    ---------- Post added at 06:29 PM ---------- Previous post was at 06:29 PM ----------

    Quote Originally Posted by mutter View Post
    echo "Total Accounts: ".$execquery " - ";
    change to echo "Total Accounts: ".$execquery." - ";
    If I use that then you get:

    PHP Code:
    <?php
    $connection 
    odbc_connect('GunzDB','sa''password'
    or die(
    'Cant connect to the server');
    $sqlquery="SELECT COUNT(*)  FROM Account";
    $execquery=odbc_exec($connection,$sqlquery);
    echo 
    "Total Accounts: ".$execquery." - "

    //close connection
    odbc_close($connection);

    ?>
    In the site I get this:

    PHP Code:
    Total AccountsResource id #3 - 
    Last edited by BGRick; 22-02-11 at 07:10 PM.

  3. #18
    Member mutter is offline
    MemberRank
    Dec 2010 Join Date
    ArgentinaLocation
    64Posts

    Re: [PHP] Total Accounts & Characters

    Quote Originally Posted by BGRick View Post
    I don't get this one o.o

    ---------- Post added at 06:29 PM ---------- Previous post was at 06:29 PM ----------



    If I use that then you get:

    PHP Code:
    <?php
    $connection 
    odbc_connect('GunzDB','sa''24maart!'
    or die(
    'Cant connect to the server');
    $sqlquery="SELECT COUNT(*)  FROM Account";
    $execquery=odbc_exec($connection,$sqlquery);
    echo 
    "Total Accounts: ".$execquery." - "

    //close connection
    odbc_close($connection);

    ?>
    In the site I get this:

    PHP Code:
    Total AccountsResource id #3 - 
    Oh my bad.

    PHP Code:
    <?php
    $cxn 
    odbc_connect("GunzDB""sa""pass");
    $sql "SELECT * FROM Account'";
    $res odbc_exec($cxn$sql);
    $items 0;
     while (
    $row odbc_fetch_array($res))
       {
           
    $items++;                          
       } 
      
    odbc_free_result($res);
      echo 
    "<br>total No. of rows: $items";
    ?>
    PHP: odbc_num_rows - Manual

  4. #19
    Account Upgraded | Title Enabled! BGRick is offline
    MemberRank
    Oct 2010 Join Date
    The NetherlandsLocation
    437Posts

    Re: [PHP] Total Accounts & Characters

    That gives errors like hell...

  5. #20
    Member mutter is offline
    MemberRank
    Dec 2010 Join Date
    ArgentinaLocation
    64Posts

    Re: [PHP] Total Accounts & Characters

    PHP Code:
    <?php
    $con 
    odbc_connect
    ("Driver={SQL Server};
    Server={host\SQLEXPRESS};
    Database={GunzDB}"
    ,
     
    samypass) or die();
     
    # function num_rows ODBC 
    function num_rows($query)
    {
        
    $items 0;
        while( 
    odbc_fetch_row($query) )
        {
            
    $items++;
        }
        
    odbc_free_result($query);
        return 
    $items;
    }

    # account
    $sql "SELECT * FROM Account";
    $res odbc_exec($con$sql);
     
    # char
    $sql2 "SELECT * FROM Character";
    $res2 odbc_exec($con$sql2);
     
    # clan
    $sql3 "SELECT * FROM Clan";
    $res3 odbc_exec($con$sql3);

    $acc num_rows($res);
    $char num_rows($res2);
    $clan num_rows($res3);

      echo 
    "Nº total of accounts: ".$acc;
      echo 
    "<br>";

      echo 
    "Nº total of characters: ".$char;
      echo 
    "<br>";

      echo 
    "Nº total of clans: ".$clan;
      echo 
    "<br>";

    ?>
    Last edited by mutter; 22-02-11 at 07:41 PM.

  6. #21
    Account Upgraded | Title Enabled! BGRick is offline
    MemberRank
    Oct 2010 Join Date
    The NetherlandsLocation
    437Posts

    Re: [PHP] Total Accounts & Characters

    That didn't worked but with your script I got it working ;)

    PHP Code:
    <?php include ("config.php"?>
    <?php
     
    # function num_rows ODBC 
    function num_rows($query)
    {
        
    $items 0;
        while( 
    odbc_fetch_row($query) )
        {
            
    $items++;
        }
        
    odbc_free_result($query);
        return 
    $items;
    }

    # account
    $sql "SELECT * FROM Account";
    $res odbc_exec($connect$sql);
     
    # char
    $sql2 "SELECT * FROM Character";
    $res2 odbc_exec($connect$sql2);
     
    # clan
    $sql3 "SELECT * FROM Clan";
    $res3 odbc_exec($connect$sql3);

    $acc num_rows($res);
    $char num_rows($res2);
    $clan num_rows($res3);

      echo 
    "Nº total of accounts: ".$acc;
      echo 
    "<br>";

      echo 
    "Nº total of characters: ".$char;
      echo 
    "<br>";

      echo 
    "Nº total of clans: ".$clan;
      echo 
    "<br>";

    ?>
    Config.php:
    PHP Code:
    <?php
    $dns
    ="GunzDB";
    $user="sa";
    $pass="password";
    $connect=odbc_connect($dns$user$pass) or die ("Couldn't connect to the database, we're sorry..."); 
    odbc_exec($connect,"use GunzDB"); 

    ?>
    So thanks man!

    /close request



Page 2 of 2 FirstFirst 12

Advertisement