Jump to content


Photo

Can I do this with php...?


  • Please log in to reply
9 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 24 April 2006 - 11:22 PM

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?

#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 24 April 2006 - 11:28 PM

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
If you're not part of the solution, you're part of the precipitate

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 25 April 2006 - 12:46 AM

[!--quoteo(post=368204:date=Apr 24 2006, 07:28 PM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Apr 24 2006, 07:28 PM) View Post[/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.

#4 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 25 April 2006 - 12:51 AM

Do you use a database to keep track of your members?
If you're not part of the solution, you're part of the precipitate

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 25 April 2006 - 06:10 AM

[!--quoteo(post=368234:date=Apr 24 2006, 08:51 PM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Apr 24 2006, 08:51 PM) View Post[/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.

#6 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 25 April 2006 - 09:34 AM

Im assuming that your using mysql:

Make a table called counter with the fields count_id and count_num

CREATE TABLE `counter` (
`count_id` INT( 25 ) NOT NULL AUTO_INCREMENT ,
`count_num` VARCHAR( 200 ) NOT NULL ,
PRIMARY KEY ( `count_id` )
) TYPE = MYISAM;

Insert your first value

INSERT INTO counter( count_num )
VALUES (
'40000'
)

The id for this counter will be 1

somewhere on the page that you're counting, use the following script

$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());

If you're not part of the solution, you're part of the precipitate

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 11:56 AM

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 '40000' NOT NULL ,
) TYPE = 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] INTO `counter` VALUES (40000); [!--sql2--][/div][!--sql3--]

The update in your PHP code would be:
<?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());
?>

Ken

#8 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 26 April 2006 - 01:06 AM

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.

#9 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 26 April 2006 - 01:58 AM

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.

#10 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 26 April 2006 - 04:13 AM

[!--quoteo(post=368389:date=Apr 25 2006, 11:56 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 25 2006, 11:56 PM) View Post[/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....
If you're not part of the solution, you're part of the precipitate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users