Re: mySQL query question
| From: | Jochem Maas | Date: | Fri, 14 Nov 2008 07:46:02 +0000 |
| Subject: | Re: mySQL query question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283281@lists.php.net to get a copy of this message | ||
Michael S. Dunsavage schreef:
> okay I want to pull an integer from a database called confirm_number,
> add 1 and repost it back to the database
>
>
> here's the code I'm using.
>
>
> $queryconfirm="SELECT confirm_number from contacts ORDER BY contact DESC
> LIMIT 1";
> $confirmresult=$queryconfirm;
>
> now here's the problem
>
> I want to add 1 to confirm_number:
>
> $confirm_number=$confirmresult;
> $confirm_number+=1;
>
> Now all this does is set the confirm_number record to 1 in the database.
> So I assume that $queryconfirm somehow is not being passed to
AFAIKT your not querying the DB at all and your merely adding 1 to a string,
which results in 1.
adding 1 to a php variable will never cause and update in a database ...
well actually there might be a way to do that but I can't think of it using
some kind of hyper funky object but I'm pretty sure there is no way to
overload the + operator.
> confirm_number? But, while we're here the confirm_number is supposed to
> be 5 digits long and the +1 should make it 10001, 10002, 10003 etc
>
> how would I set the original number to 1000 to begin with? Or should I
> just set that in the database record its self when I'm ready to use the
> website?
1000 + 1 != 10001
you might consider setting a default of 1000 or 10000 or whatever on the given
field so it's automatically populated with that number when a contact record is
created.