PHP/Mqsql - Countdown from 1000??

Discussion in 'PHP' started by bigredkacy, Oct 29, 2009.

  1. #1
    Im making a form where a user can add their email
    Is it possible to count each one added and subtract one?

    For example
    user1 adds email - count goes to 999 echos it on registration page
    .
    .
    .
    user 400 adds email - count goes to 600 and echos it on registration page

    How can this work?

    www.integyfacts.com/betafolder is the form

    Kacy
     
    bigredkacy, Oct 29, 2009 IP
  2. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The easiest way to do this would be to use the COUNT function to select the number of rows in the email table, and then subtract that from 1,000.
     
    organicCyborg, Oct 29, 2009 IP
  3. bigredkacy

    bigredkacy Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you i will attempt
     
    bigredkacy, Oct 29, 2009 IP
  4. bigredkacy

    bigredkacy Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So i did this. and i have 3 rows and its showing -997 how do i make it positive?
            <?php
            $result = mysql_query("SELECT * FROM user");
    
             $num_rows = mysql_num_rows($result);
             
             echo $num_rows -= 1000;
    
    
    
            ?>
    PHP:
    www.integyfacts.com/betafolder
     
    bigredkacy, Oct 29, 2009 IP
  5. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try this query instead: "SELECT COUNT(*) FROM user", and then store that number in a variable.

    
    echo 1000 - $userCount;
    
    Code (markup):
    is what you're going after, not $userCount - 1000
     
    organicCyborg, Oct 29, 2009 IP
  6. bigredkacy

    bigredkacy Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Got it!!

    Thank you

     
    Last edited: Oct 29, 2009
    bigredkacy, Oct 29, 2009 IP
  7. mike30

    mike30 Well-Known Member

    Messages:
    887
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    140
    #7
    Here we go...
    <?php 
    	/*======================================================================*\
    	|| #################################################################### ||
    	|| # Wihee 1.0.0 													  # ||
    	|| # File Version 1.0.0												  # ||
    	|| # File Name: class.counter.php										  # ||
    	|| # Date created: October 30, 2009         						  # ||
    	|| # Date last updated: October 30, 2009        					  # ||
    	|| # ---------------------------------------------------------------- # ||
    	|| # Author: Miguel Fernandez. 	(Mike30)						      # ||
    	|| # This file may be redistributed in whole or significant part.     # ||
    	|| # ------------------------- WIHEE SOFTWARE ----------------------- # ||
    	|| #            http://www.wihee.com | http://www.wihee.net           # ||
    	|| #################################################################### ||
    	\*======================================================================*/
    
    	//////////////////////////////////////////////////////////////////////////
    	/* 
    	// This script returns a count down form a Mysql database table
    	// here is the table to use:
    	
    --
    -- Table structure for table `counter`
    --
    
    CREATE TABLE IF NOT EXISTS `counter` (
      `id` int(6) NOT NULL auto_increment,
      `count_down` int(6) default '1000',
      `counter` int(6) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    
    		
    	*/
    	//////////////////////////////////////////////////////////////////////////
    	
    	##########################################################################
    	# INSTRUCTIONS
    	##########################################################################
    	/*
    	
     	 1- create the count table above in your mysql database
    	 2- Include this script on your form handler
    	 3- Update the details of your database bellow.
    	 
    	  */
    	 ##########################################################################
    
    	class counter{
    	
    	// properties
    	var $deduct;
    	
    	
    	
    		function counter($counter_number, $deduct_amount){
    				$this->hostname_db = "localhost";
    				$this->database_db = "db_testing";
    				$this->username_db = "root";
    				$this->password_db = "rootwdp";
    				$this->dbc = mysql_pconnect(
    					$this->hostname_db, 
    					$this->username_db, 
    					$this->password_db) or trigger_error(mysql_error(),E_USER_ERROR);
    				
    				$this->dabselect = mysql_select_db($this->database_db, $this->dbc);
    				$this->sql = 'UPDATE counter SET count_down=count_down-'.$deduct_amount.' WHERE id = '.$counter_number.'';
    				$this->deduct = mysql_query($this->sql, $this->dbc) or die(mysql_error());
    				
    				
    			
    				
    				
    				
    				}// end of counter method
    	
    	}// end of class
    	
    	
    	// creates the object and update the counter
    	// @param Decuct Amount
    	// @param The counter id
    	
    	// so you can use more than one counter, just change the parameres
    	$new_number = new counter(1,1);
    	$new_number->deduct;
    
    ?>
    ?>
    PHP:
     
    Last edited: Oct 30, 2009
    mike30, Oct 30, 2009 IP
  8. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8

    i think you are becoming class happy.
     
    baris22, Oct 30, 2009 IP