| Pages: [1] :: one page |
| Author |
Thread Statistics | Show CCP posts - 0 post(s) |

Tsuna Lamperouge
Amarr
|
Posted - 2010.12.10 11:45:00 -
[1]
So I made my own lotto tracking app for my website using php + mysql to fetch the api data and save it to a table and from there assign tickets in another table. My main problem is that I want to assign unique id's between 1 and the max ticket number. I've tried to do a loop to generate the number again and if it exists generate again and again until it doesnt exist but to no success I was wondering if anyone here could shed some light here and help me get this working 
|

Lutz Major
Austriae Est Imperare Orbi Universo
|
Posted - 2010.12.10 11:57:00 -
[2]
INSERT INTO tickets (ticketNumber, userID) SELECT MAX(tickets) + 1, ? FROM tickets
|

Tsuna Lamperouge
Amarr
|
Posted - 2010.12.10 12:11:00 -
[3]
I dont think you understood me quite well so ill try to explain it again. Im trying to make a loop that will generate a ticket number then check in the database if it's taken if it is generate a new one if it isnt assign that ticket number to the ticket table. I've already got a function that returns a true or false if the ticket already exists my main problem is getting the loop to work like intended. (It assigns the same ticket number most of the time). (Loop should generate a new number each time if the ticket = true and stop when it doesnt exist and assign that number)
|

Lutz Major
Austriae Est Imperare Orbi Universo
|
Posted - 2010.12.10 12:16:00 -
[4]
Originally by: Tsuna Lamperouge Im trying to make a loop that will generate a ticket number then check in the database if it's taken if it is generate a new one if it isnt assign that ticket number to the ticket table.
Why do you generate a ticket number outside of the database (before asking the database) in the first place?
Try to get all free tickets - pick one and then insert the new one?
|

Thumiel Zaul
The Resident Haunting C0NVICTED
|
Posted - 2010.12.10 12:37:00 -
[5]
Edited by: Thumiel Zaul on 10/12/2010 12:37:56 try the following in sql (not sure if you can use stored procedures, if you can it'll go in one of those nicely or even a function)
If not exists (Select TicketNumber from Tickets where TicketNumber = @TicketNumber) { Insert into Tickets (TicketNumber, UserID) Values (@TicketNumber, @UserID) } Select TicketNumber from Tickets where TicketNumber = @TicketNumber and UserID = @UserID
Just check for null values on the sql return, as if the ticket already exists, it wont exist for the current user and will therefore return null.
I know this may not be the most uber code in the world, so before any one jumps on it !DISCALIMER!
-edit for spelling and grammar
|

Tsuna Lamperouge
Amarr
|
Posted - 2010.12.10 12:44:00 -
[6]
Edited by: Tsuna Lamperouge on 10/12/2010 12:46:11 @ Lutz :Hasn't occured to me to try your method thx for the help I'll look into that since it seems more efficient than my way @Thumiel : I'll look into trying your method too thx!
|

Freeholder Joe
|
Posted - 2010.12.11 21:48:00 -
[7]
Originally by: Tsuna Lamperouge So I made my own lotto tracking app for my website using php + mysql to fetch the api data and save it to a table and from there assign tickets in another table. My main problem is that I want to assign unique id's between 1 and the max ticket number. I've tried to do a loop to generate the number again and if it exists generate again and again until it doesnt exist but to no success I was wondering if anyone here could shed some light here and help me get this working 
create an auto_increment index field at the start of your table...
// do some query, ignoring the index value as its automatic
echo 'Ticket #:' . mysql_insert_id();
|
| |
|
| Pages: [1] :: one page |
| First page | Previous page | Next page | Last page |