![]() |
Need help creating a function
How can I make a function out of the code below but continue to cycle until it gets a number that does not exist.
PHP Code:
|
By just putting a do while loop around the entire thing will make it able to repeat. Just make the while statement while ($numrows >= 1).
On a side note why don't you just make one column in the db an auto increment field that would remove all this extra making up numbers. Also this could run for quite a few queries if you were to get a large amout of the numbers added, or run forever if all of them are added. |
The number being generated is an incident report number that the user uses to refer back to there report. The client wanted it similar to say when you pay a bill online and get the payment number.
I don't understand too much about php right now, but I'll try replacing the if to a while like you said. Thank you |
When I change if ($numrows < 1 ) to while ($numrows >= 1) it doesn't display the number nor does it display the rest of my form. Any thoughts?
|
What are you are trying to do?
|
In theory I am try to generate a random number, then check the db to see if that number exist; if that number exist then to generate a new number and check to see if that one exist. Doing that process until it generates a number that does not exsit to use as a report number.
|
Ye you really should look at putting another field in the db (normally the key field) and add auto increment to that. Then as a report number you can just add zeros to the front when you display it to the screen, this just makes all the numbers seem more "legit" so in the database it would be 1, 2, 3... and to the users the report number would be 00001, 00002, 00003...
|
1 Attachment(s)
Taking the above ideas into consideration. How about the following? To get it working, merely import the attached SQL file and then change the MySQL details on lines 43 and 44.
php Code:
MySQL table creation code if you don't wish to download the SQL file: sql Code:
|
| All times are GMT. The time now is 12:54 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0