hostfreak Posted April 24, 2006 Share Posted April 24, 2006 I'm making a page that I want to have a number on it called Trip number. Everytime the page is opened by a member I want it to be able to have that number increment by one starting at 40,000. I don't need the number tracked in a database or anything because it will be on a email form that will get printed by the user and sent to the admin. So is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/ Share on other sites More sharing options...
sanfly Posted April 24, 2006 Share Posted April 24, 2006 I think that you will need to keep in a database, otherwise you have no way of keeping track of what number you should be up to Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30321 Share on other sites More sharing options...
hostfreak Posted April 25, 2006 Author Share Posted April 25, 2006 [!--quoteo(post=368204:date=Apr 24 2006, 07:28 PM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Apr 24 2006, 07:28 PM) [snapback]368204[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think that you will need to keep in a database, otherwise you have no way of keeping track of what number you should be up to[/quote]I see. I just don't know how I would ge the database to know since no information will be entered into a database from that page. It will just be sent through an email. Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30346 Share on other sites More sharing options...
sanfly Posted April 25, 2006 Share Posted April 25, 2006 Do you use a database to keep track of your members? Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30351 Share on other sites More sharing options...
hostfreak Posted April 25, 2006 Author Share Posted April 25, 2006 [!--quoteo(post=368234:date=Apr 24 2006, 08:51 PM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Apr 24 2006, 08:51 PM) [snapback]368234[/snapback][/div][div class=\'quotemain\'][!--quotec--]Do you use a database to keep track of your members?[/quote]Yeah I do. It's just that I don't need none of the information on the page recorded since they will print it before they send and the information will be sent to an email. I'm a bit confused on this. Thanks for taking the time so far. Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30414 Share on other sites More sharing options...
sanfly Posted April 25, 2006 Share Posted April 25, 2006 Im assuming that your using mysql: Make a table called counter with the fields count_id and count_num[code]CREATE TABLE `counter` (`count_id` INT( 25 ) NOT NULL AUTO_INCREMENT ,`count_num` VARCHAR( 200 ) NOT NULL ,PRIMARY KEY ( `count_id` )) TYPE = MYISAM;[/code]Insert your first value[code]INSERT INTO counter( count_num )VALUES ('40000')[/code]The id for this counter will be 1somewhere on the page that you're counting, use the following script[code]$r = mysql_query("SELECT count_num FROM counter WHERE count_id = '1'") or die("SELECT ERROR: " . mysql_error()); $row = mysql_fetch_array($r); $new_count = $row['count_num'] + 1; $r = mysql_query("UPDATE counter SET count_num = '$new_count' WHERE count_id = '1'") or die("UPDATE ERROR: " . mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30458 Share on other sites More sharing options...
kenrbnsn Posted April 25, 2006 Share Posted April 25, 2006 Why even have two fields in the table. Just have one, "count_num". There's only going to be one record in the table anyway, so theres no need for an autoincremented id. Why did you make "count_num" a varchar and not an int?This would change the table to:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]CREATE TABLE `counter` (`count_num` int(5) DEFAULT [color=red]'40000'[/color] NOT NULL ,) TYPE [color=orange]=[/color] MYISAM; [!--sql2--][/div][!--sql3--]The insert would then become:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']INSERT[/span] [color=green]INTO[/color] [color=orange]`counter`[/color] VALUES (40000); [!--sql2--][/div][!--sql3--]The update in your PHP code would be:[code]<?php$q = "SELECT count_num FROM counter");$r = mysql_query($q) or die("SELECT ERROR: $q<br>" . mysql_error());$row = mysql_fetch_array($r);$new_count = $row['count_num'] + 1;$q = "UPDATE counter SET count_num = $new_count";$r = mysql_query($q) or die("UPDATE ERROR: $q<br>" . mysql_error());?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30503 Share on other sites More sharing options...
hostfreak Posted April 26, 2006 Author Share Posted April 26, 2006 Thanks guys, I really appreciate the help. I might do the count_id though, that way i can insert the id_num of the member to make the number unique to the member. Once again, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30787 Share on other sites More sharing options...
SieRobin Posted April 26, 2006 Share Posted April 26, 2006 Why not just set an ID for each member and have it auto increment? Then you really don't have to do anything at all. Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30801 Share on other sites More sharing options...
sanfly Posted April 26, 2006 Share Posted April 26, 2006 [!--quoteo(post=368389:date=Apr 25 2006, 11:56 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 25 2006, 11:56 PM) [snapback]368389[/snapback][/div][div class=\'quotemain\'][!--quotec--]Why even have two fields in the table. [/quote]So if you ever want another counter for anything, its all set up. Thinking ahead.... Quote Link to comment https://forums.phpfreaks.com/topic/8316-can-i-do-this-with-php/#findComment-30836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.