Jump to content

Simple SQL question


waynew

Recommended Posts

For some reason, it's not working:

 

Here's my update code:

 

<?php

else if($end_result[$i] == 2){
           echo "GIVEN TO AWAY";
           $give_away = mysql_query("UPDATE c_table SET POINTS = (POINTS+3) WHERE TEAM = $away[$i]") or die(mysql_error());
}

?>

 

I know for a fact that the if statement is being proven true as the echo tells me.

 

However, when I try to take the teams out:

 

<?php
$select_all = mysql_query("SELECT * FROM c_table ORDER BY POINTS") or die(mysql_error());

while($row = mysql_fetch_assoc($select_all)){
    
	echo "<TR>";
	echo "<TD>".get_team_name($row['TEAM'])."</TD><TD>".$row['POINTS']."</TD>";
	echo "</TR>";

}
?>

 

All I'm getting is the name of the teams and no points.  ???

Link to comment
https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605493
Share on other sites

Is TEAM a numeric data type? If not, then $away[$i] must be enclosed in single-quotes. Without the single quotes $away[$i] is being evaluated as a number and if it is a string without any leading digits, ends up being a zero or a NULL and the comparison won't match any of your TEAM values.

 

Also, echo out your query string to make sure it contains what you expect, $away[$i] might not be what you think it is.

Link to comment
https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605504
Share on other sites

TEAM is numeric. It's the ID of a team.

I echoed out the query and it looks like expected.

The failure is happening on the update. I ran mysql_affected_rows( ) and it gave me a 0.

The arrays coming in are correct.

The array value that determines what update to do is correct.

 

So I'm stumped. The teams are in the DB but I can't update the column POINTS.

 

mysql_query("CREATE TEMPORARY TABLE c_table(TEAM INT(24) UNIQUE, POINTS INT(24), PLAYED INT(24))") or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605505
Share on other sites

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.