need to loop this properly can someone help?

so ive been working on this code here and it works perfectly fine what it does is pull a credit that has been deposited into a acount in sql but if multiple credits is uploaded it still only pulls 1 credit if i reload it it will keep deducting the credits on every reload what i wanna do is have it loop or load intill all the credits are gone can someone please please help me with this:

include “connect.php”;
include “config.php”;

$sql_query = “SELECT * FROM walletJournal”;
$sql_res = mysql_query($sql_query);
while ($row = mysql_fetch_array($sql_res)) {
$date = ($row[‘date’]);
$refID = ($row[‘refID’]);
$ownerID1 = ($row[‘ownerID1’]);
$ownerName1 = ($row[‘ownerName1’]);
$processed = ($row[‘processed’]);
$done = ($row[‘done’]);

if ( $processed > 0 ) {

mysql_query("INSERT INTO tickets (owner_id, ownerName1, refID, date) VALUES ('$ownerID1', '$ownerName1' , '$refID', '$date')") or die(mysql_error());
mysql_query("UPDATE walletJournal SET done=1 WHERE refID=$refID") or die(mysql_error());

$ticket_issue = 1;
$sum = $processed - $ticket_issue;
mysql_query("UPDATE walletJournal SET processed=$sum WHERE refID=$refID") or die(mysql_error());
}

}

// SET PRIZE FUND //
$sql_query = “SELECT COUNT(ticket_id) FROM tickets”;
$sql_res = mysql_query($sql_query) or die(mysql_error());
while ($row = mysql_fetch_array($sql_res)) {
$count = ($row[‘COUNT(ticket_id)’]);

$total = $count * $ticket_price;
$count1 = $total / 100;
$count2 = $count1 * $commision;

$prize1 = $total - $count2;
$prize = $prize1 + $kickstart;

mysql_query(“UPDATE lottery SET prize=$prize WHERE active=1”) or die(mysql_error());

}

?>

Sponsor our Newsletter | Privacy Policy | Terms of Service