mysql - PHP weight SQL results -


This may be a bit confusing, but bare here with me.

I have a mysql table that I store a column ( ticket ), and the ticket can be in any number.

What I would like to do is a mysql query that chooses all the rows from the column, sorting them in descending order, and then the result of the query uses PHP for "weight" so that the top < Chance of being more selected in the row with the code> ticket value.

It seems very confusing. Essentially, in a high number of tickets , it is a high chance to be chosen.

Is there any way to do this by using procedural mysqli to pick rows and pick the tickets for PHP? All inputs are accepted.

The query is not what you want, which is essentially a weighted Random selection It looks like what you need to do is select all the rows and they are called numerically indexed array, where x numbers of rows are present which are placed in X-rays in different indices. You then choose that randomly select a number between 0 and [ARRAY_SIZE - 1] to set the row.

The query may appear:

  SELECT id, ticket from the table  

where id The primary key for the table will be.

And the code can look like this:

  // Your DB query logic here // proceed with the following code, if the non-empty result set is returned / / Select array $ array_ array = array; While ($ line = / * your DB line fetch system here) / $ {$ temp = array_fill (0, (int) $ line ['ticket'], $ line ['id']); $ Selection_array = array_merge ($ selection_aire, $ temp); } // array $ random = Choose a value from rand (0, count ($ selection_array) - 1); $ Selected_id = $ selection_array [$ random];  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -