Jump to content

Simple SQL question


waynew

Recommended Posts

Simple question. Tried Googling but always ended up with the wrong question being answered.

 

Say I just want to add to a column's value.

 

Would this work?

 

$give_home = mysql_query("INSERT INTO c_table (POINTS) VALUES ((POINTS+3)) WHERE TEAM = '$home[$i]'");

Link to comment
Share on other sites

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
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
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
Share on other sites

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.