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
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.
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
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
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: