I'm pretty new to PHP, I'm trying to build a sort of lottery system for a contest.Users log in, then enter a form. On the form they enter 3 values. Date, invoice number, and total sales on the invoice.These three values then get translated to the variables saledate, invoicenumber, and howmanysold.The new variables are then validated, collected and, in addition to the userid linked to the account that is currently logged in, are saved to a database.\[code\]function InsertBallotIntoDB(&$formvars, $user_rec) { $insert_query = 'insert into `entries` ( `user_id`, `saledate`, `invoicenumber`, `howmanypad` ) values ( "' . $this->SanitizeForSQL($user_rec['id_user']) . '", "' . $this->SanitizeForSQL($formvars['saledate']) . '", "' . $this->SanitizeForSQL($formvars['invoicenumber']) . '", "' . $this->SanitizeForSQL($formvars['howmanysold']). '" )'; if(!mysql_query( $insert_query ,$this->connection)) { $this->HandleDBError("Error inserting data to the table\nquery:$insert_query"); return false; } return true;}\[/code\]How the contest system works is as follows:Each item sold equates to one ballot entered into the database, and then at the end of the month, one random ballot is chosen.Right now, my code submits one query to the database based on the form. I've tried searching the web, but I cant think of a solution on how to make howmanysold = ballotsMy only idea is to read the user_id and invoice number, and copy them to a new database X amount of times. Where X is the howmanysold column for a row.But I have two problems with this, 1) I have absolutely no idea how to go about selecting from one table, then taking a variable Z and inserting Z queries to a new table using X data from table12)Isnt there a simpler way to do this? Making two tables is the only way i can think of, but I dont know the full power of PHP, so any pointers in the right direction would really help.