hi All,

I hope someone can help me with this.

I have been struggling with it and searching for a solution, but I am such a newb that I am probably going about it all wrong.

If number exists in table pw_reg, generate a new random number and check again. Keep checking until an unused number is found.


else {

$randnumber = rand($rand1,$rand2);

$n_query ="SELECT * FROM pw_reg WHERE pcode='$randnumber'";
$n_result = mysql_query($n_query);

$numrows = mysql_num_rows($n_result);

if($numrows != 0) {

What do I put in here ?

}

else {

Pleeeese

Thom

    Well, I guess you could put the whole lot inside a loop, but it's going to be very inefficient and might time out on you if it keeps randomly matching values in the DB. If you care to tell us what it is, functionally, that you are trying to accomplish, I suspect we can come up with a more optimal solution.

      NogDog wrote:

      Well, I guess you could put the whole lot inside a loop, but it's going to be very inefficient and might time out on you if it keeps randomly matching values in the DB. If you care to tell us what it is, functionally, that you are trying to accomplish, I suspect we can come up with a more optimal solution.

      hi NogDog,

      Thanks for looking at this 🙂

      It is a for an online prize draw.

      The winning tickets are generated from a range of random numbers and published.

      Then this is part of the code that generates the entry numbers from the same range of random numbers when a link is clicked on.

      And instantly tells the participant if they have won a prize or not.

      I have it all setup and working, but what is happening is that when a number is drawn it is not excluded from the contest, the same number can be drawn again.

      I have it set so it does not award the prize again but I would like once a number is drawn it cannot be drawn again.

      I hope I explain this clearly 🙂

      Thom

        Write a Reply...