USERNAME:
PASSWORD:
Save Info!
Logging in…
This topic is 1 page long.
[ Profile | Posts | Contact ]
Posted at: 7/28/09 06:37 PM
Sign-Up: 06/30/08
Posts: 2,167
What I'm trying to do is generate a unique id for every user on the site.
I want this script to select the highest id and raise it by one, but when I run the script "$myfetch" and "$genid" are always equal to 1 no matter what.
I know that the mysql query is correct because I used it in phpMyAdmin and it worked fine.
//generate an id $query = mysql_query("SELECT userid FROM users ORDER BY userid DESC LIMIT 1"); $myfetch = mysql_fetch_array($query); $genid = (int)$myfetch++;
The following sentence is true. The previous sentence is false. O_o PARADOX! Linux Users Club | Linketylinklinklinklink...
Posted at: 7/28/09 06:58 PM
Sign-Up: 01/30/07
Posts: 3,948
As far as I know you can't simply cast and array as an int! Why not use auto increment or simply generate a random number using the system time as the seed value...
PHP Main :: C++ Main :: Java Main :: irc.freenode.net
Posted at: 7/28/09 07:14 PM
Sign-Up: 08/26/03
Posts: 5,873
Like Jon-86 said, you can set the row userid to auto_increment. Every time a new user is created it will automatically make the next ID one higher than the last.
If you want to get the highest userid, you could use MAX:
$maxID = mysql_query("SELECT MAX(userid) AS maxID FROM users"); $maxIDQ = mysql_fetch_array($maxID);
I'm not an expert in this, but I am using this in a stat generating file on my site.
|| AK || TX || NG Archive - The Problems of the Past, Today! I'm too lazy to upload a non-frosted sig...
Posted at: 7/28/09 07:15 PM
At 7/28/09 06:58 PM, Jon-86 wrote: As far as I know you can't simply cast and array as an int! Why not use auto increment or simply generate a random number using the system time as the seed value...
Fixed, I didn't know about auto increment...
Posted at: 7/28/09 08:42 PM
Sign-Up: 03/09/06
Posts: 1,891
At 7/28/09 07:15 PM, bgraybr wrote: At 7/28/09 06:58 PM, Jon-86 wrote: As far as I know you can't simply cast and array as an int! Why not use auto increment or simply generate a random number using the system time as the seed value...Fixed, I didn't know about auto increment...
Just about Database i've used i alwaays have Id Auto increment and Primary Key :)
awww
Posted at: 7/29/09 12:29 AM
Sign-Up: 02/14/05
Posts: 2,830
At 7/28/09 07:15 PM, bgraybr wrote: Fixed, I didn't know about auto increment...
Every time you insert something into table, the new entry will have +1 higher than last. Hurrah!
over 1000 brains since 2005 Mich's Audio Guide By the demanding force of audio fags, I have placed this here.
Posted at: 7/29/09 10:08 AM
Sign-Up: 09/10/04
Posts: 3,670
While you are learning new things, learn parameterized queries, you sound like the kind of guy who would forgot escaping stuff. With parameterized queries, you will never have to worry about sql injections. However, you need a serious database extension to use those. PDO and mysqli is two extensions for php that does support it. Look for "prepared queries", the name of the implementation technique.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
Posted at: 7/30/09 04:38 PM
Sign-Up: 02/04/09
Posts: 39
If you want a unique Id for every person . you can use data of field primary key in mysql. and I hope your problem can be solved thank for join us. ---- FriendyAnil
SEO--SEO
Posted at: 7/30/09 08:01 PM
Sign-Up: 01/22/08
Posts: 781
At 7/30/09 04:38 PM, rockymeet wrote: If you want a unique Id for every person . you can use data of field primary key in mysql. and I hope your problem can be solved thank for join us. ---- FriendyAnil
Work on your English a bit, and put FriendyAnil or whatever in your signature.
And he's not really "joining us"..
Camp North | PHP: Main | AS3: Main
All times are Eastern Standard Time (GMT -5) | Current Time: 02:15 PM
<< Back