Jump to content

MySQL INSERT - Not executing some queries, suspected concoct problem


MasterACE14

Recommended Posts

good afternoon,

 

I have a cron job which runs hourly and does a few MySQL queries, I have a mix of normal queries eg. mysql_query("""); and ADOdb queries

eg. $db->execute("");

 

The part of the code that isn't working is the part that relates to "Jousting".

 

here it is(relevent code only):

<?php

// workout which knight won the joust, and workout joust winners and give them there gold
$joust_rand = rand(1,2);

// declare winner
if($joust_rand == 1) { $winner = "henry"; }
elseif($joust_rand == 2) { $winner = "richard"; }

// select all fields from joust
$joust_query = mysql_query("SELECT * FROM `jousting` WHERE `id`=1 LIMIT 1");

// select all winners from players
$joust_winners = mysql_query("SELECT * FROM `players` WHERE `bet_knight`='$winner'");

// make available all fields in jousting
while($rows = mysql_fetch_array($joust_query)) 
{
// make available all fields in players(who were winners)
while($winner_is = mysql_fetch_array($joust_winners))
{
// if the winner was henry, do all the queries and gold dividing
if($winner == "henry") 
{ 

$none = "none";

// winner full name
$winner_name = "Sir, Henry";

$loser_name = "Sir, Richard";

// divide all gold bet on henry between winners
$divide_gold = $winner_is['bank'] + ($rows['bets_knight1'] / mysql_num_rows($joust_winners));

$query_jousta = $db->execute("update `jousting` set `knight1_wins`=`knight1_wins`+1, `winner`=? WHERE `id`=1 LIMIT 1", array($winner_name));

$query_joustb = $db->execute("update `players` set `bank`=?, `bet_gold`=0, `bet_knight`=? WHERE `id`=1 LIMIT 1", array($divide_gold,$none));

$queryc = $db->execute("update `jousting` set `bets_knight1`=0, `bets_knight2`=0, `winner`=?, `loser=? WHERE id=1", array($winner_name,$loser_name));

}

// if the winner was richard, do all the queries and gold dividing
elseif($winner == "richard")
{

$none = "none";

// winner full name
$winner_name = "Sir, Richard";

$loser_name = "Sir, Henry";

// divide all gold bet on richard between winners
$divide_gold = $winner_is['bank'] + ($rows['bets_knight2'] / mysql_num_rows($joust_winners));

$query_jousta = $db->execute("update `jousting` set `knight2_wins`=`knight2_wins`+1, `winner`=? WHERE `id`=1 LIMIT 1", array($winner_name));

$query_joustb = $db->execute("update `players` set `bank`=?, `bet_gold`=0, `bet_knight`=? WHERE `id`=1 LIMIT 1", array($divide_gold,$none));

$queryc = $db->execute("update `jousting` set `bets_knight1`=0, `bets_knight2`=0, `winner`=?, `loser=? WHERE id=1", array($winner_name,$loser_name));

}
}
}
// end of both while loops

?>

 

the queries that arent working are the ones that:

update the gold the player has bet(`bet_gold` field in `players` table)

update who lost the joust(`loser` field in `jousting` table)

update the wins for the winning knight(`knight1_wins` or `knight2_wins` fields in `jousting` table)

 

the rest seems to be working fine, i think... may of missed something  :-\

 

I believe the problem is the way I have concocted variables into the queries. whether I do it like " . $var . " or ' . $var . ' or $var or '$var' I'm just not sure.

 

note: I dont receive any parse errors or any errors of any kind.

 

Thanks in advance

 

Regards ACE

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.