I have the following code:
$GetUID = $c->query("SELECT UserUID FROM dbo.Users_Master ORDER BY UserID DESC");
$UserUniqueID = $GetUID->fetch(PDO::FETCH_ASSOC);
$UUID = $UserUniqueID['UserUID'];
$NewUUID = $UUID + 1;
This is successfully working, but the problem is something with my query.
It is always entering 12 into my database.
I went to the Microsoft SQL query window and entered:
USE UserData;
SELECT UserUID FROM dbo.Users_Master ORDER BY UserID DESC
and it returned:
11, 17, 15, 19, 16, 18, 10, 13, 12, 14, 3
Which is not exactly ordering by the highest to lowest.
I then went on using:
USE UserData;
SELECT UserUID FROM dbo.Users_Master ORDER BY UserID ASC
Which returned:
3, 14, 12, 13, 10, 18, 16, 19, 15, 17, 11
I want to obtain the higest UserUID and +1 to it.. WHy is my code selecting 11 all the time?
Sounds like
UserIdis not of the datatypeint, you cancast()the value to order:See SQL Fiddle with Demo
However, the best solution is to alter the datatype in the table to match what is being stored.
To alter the table in SQL Server, you would use:
This would store the data in the correct datatype so you would not have to
cast()the value to order it.Edit #1, based on your comment that
UserIdis a varchar it seems like you mean toORDER BY UserUID DESCwhich is anint