Home > Net >  PHP generate list from sqlite database
PHP generate list from sqlite database

Time:06-02

I'm looking to generate a list with php from a Sqlite-database. The list is supposed to be used in a lottery, the tickets column are the number of tickets, and the list needs to output the user x number of times based on that (see example below)

I can't wrap my head around this, I have no problems getting an array, but how do I tackle that array and examine that to get to the end goal?

|user |tickets|
---------------
|user1| 5     |
|user2| 2     |
|user3| 1     |

Expected results

user1
user1
user1
user1
user1
user2
user2
user3

CodePudding user response:

Let's suppose you got the results from a SQLite SQL query as per your first sample above. From that, you'd read each row (usually in a while loop, so it runs until there are no more rows to read).

Then within the loop which reads the rows, you make a for loop which loops tickets number of times and echoes the user value - something like this:

for ($i = 0; $i < $tickets['tickets']; $i  )
{
  echo $tickets['user']."\n";
}
  • Related