Jump to content

Recommended Posts

Hello

 

I am having a strange problem...

 

I am running a MySQL query, and trying to pass two values from the result to a function..... it doesn't work.... it seems the variable values are not getting passed... however, if I substitute for a test variable it all works....

 

Below is the code.

 


$challengerresult2 = mysql_query("SELECT * from challenge where challenge_id = $challengeid AND status = 'completed'");
 $num_rows = mysql_num_rows($challengerresult2);
 while($row = mysql_fetch_array($challengerresult2)){
 $winnerid = $row['winner_team_id'];
 $loserid = $row['loser_team_id'];
 $winnergoals = $row['winner_num_goals'];
 $losergoals= $row['loser_num_goals'];
 $challengeteamid = $row['challenger_team_id'];
 $opponentteamid= $row['opponent_team_id'];

 mail ("[email="martyn@staggan.com"]xxxx[/email]", "RESULT", $winnergoals);

 $testvar1 = 8;
 $testvar2 = 10;

 $KO->setResByMatch( $gamenumber, $getresultsloop, $testvar1, $testvar2); // Arguments: match index, round index, score 1, score 2.
 }

 

Using testvars my function works, but if I use $winnergoals and $losergoals it doesn't. However, emailing the $winnergoals var to myself I get the right value..

 

Any ideas, I have been pulling my hair out with this

 

Thanks

This is the code I am trying to use:

 

 


$challengerresult2 = mysql_query("SELECT * from challenge where challenge_id = $challengeid AND status = 'completed'");
 $num_rows = mysql_num_rows($challengerresult2);
 while($row = mysql_fetch_array($challengerresult2)){
 $winnerid = $row['winner_team_id'];
 $loserid = $row['oppomemt_team_id'];
 $winnergoals = $row['winner_num_goals'];
 $losergoals= $row['loser_num_goals'];
 $challengeteamid = $row['challenger_team_id'];
 $opponentteamid= $row['opponent_team_id'];


 $KO->setResByMatch( $gamenumber, $getresultsloop, $winnergoals, $losergoals); // Arguments: match index, round index, score 1, score 2.
 }


 

 

This is the function being called

 


   public function setResByMatch($m, $r, $s1, $s2)
   {
    /* Sets a match result by specifying match number and round number. */

    // Test if input is valid.
    if (!$this->isMatchCreated($m, $r) ||											   // Valid round and match?
	    $this->bracket[$r][$m]['s1'] == -1 || $this->bracket[$r][$m]['s2'] == -1 ||	 // Are competitors "ready"/exist?
	    !is_int($s1) || !is_int($s2) || $s1 < 0 || $s2 < 0 || $s1 == $s2) {			 // Valid scores?
	    return false;
    }

which varaibles arn't getting passed?

have you echoed out all the results from the query?

why are you using select *?

what's the point in $num_rows?

why use mysql_fetch_array() rather than mysql_fetch_assoc() when you only address the associated keys from the query result?

OK, so $winnergoals / $losergoals are not getting passed, and I have echoed those out and emailed them to myself and they do contain number values

 

I am using select statement to get the number of goals for each team in the tournament

 

Actually $num_rows was used, it's not now....

 

I tried mysql_fetch_array and it was not working... I tried assoc because of the resource ID I was getting... and it does give me the values I want... but I am not saying I am doing it correctly...

 

So, $winnergoals / $losergoals should be passed to setResByMatch as the 3rd and 4th parameters but that function does not seem to get the values... changing $winnergoals / $losergoals to $testvar1 and $testvar2 give the expected results

That die gives me the correct values, even for the vars that were not working before... and yet if I remove the die I still get no result, but I do when using either numbers or different vars...

 

I am totally confused...

 

Also, IE was giving me loads of garbage at one point too... had to close the window and reopen it.. but Chrome was fine...

I've solved it....

 

The value coming from the dbase is a string.. (although it is an INT in the dbase) and the function requires and INT, so I have cast the done this $num1 = (int)$winnergoals and it now works....

 

How can I solve this without the additional cast?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.