waynew Posted August 1, 2008 Share Posted August 1, 2008 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 https://forums.phpfreaks.com/topic/117722-simple-sql-question/ Share on other sites More sharing options...
The Little Guy Posted August 1, 2008 Share Posted August 1, 2008 NO. Use UPDATE Try this: $give_home = mysql_query("UPDATE c_table SET POINTS = (POINTS+3) WHERE TEAM = '{$home[$i]}'"); Link to comment https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605485 Share on other sites More sharing options...
DarkWater Posted August 1, 2008 Share Posted August 1, 2008 UPDATE c_points SET points = points + 3 WHERE team = '$home[$i]' Link to comment https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605486 Share on other sites More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 That would make sense. Rolleyes. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605487 Share on other sites More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 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 More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 Bearing in mind that my table is a temporary one. Link to comment https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-605497 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2008 Share Posted August 1, 2008 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 More sharing options...
waynew Posted August 1, 2008 Author Share Posted August 1, 2008 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 More sharing options...
fenway Posted August 5, 2008 Share Posted August 5, 2008 You sure you're updating the correct row? Link to comment https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-608968 Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2008 Share Posted August 6, 2008 Without seeing all your code, I doubt we will be able to guess why it is not working. My best guess - you and your code are expecting a temporary table to persist between pages or between connections to the database. Link to comment https://forums.phpfreaks.com/topic/117722-simple-sql-question/#findComment-609286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.