kev wood Posted May 20, 2008 Share Posted May 20, 2008 is it possible to only truncate one row from a mysql table Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/ Share on other sites More sharing options...
Xurion Posted May 20, 2008 Share Posted May 20, 2008 Using TRUNCATE no, using DELETE yes. Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-545561 Share on other sites More sharing options...
kev wood Posted May 20, 2008 Author Share Posted May 20, 2008 would that still work if i only want to delete what is being stored in this row or will it just delete the row. Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-545564 Share on other sites More sharing options...
kev wood Posted May 20, 2008 Author Share Posted May 20, 2008 would the update function work better for me here as i only want to replace the data that is stored in the table. the syntax for this would be UPDATE table_name SET column_name = new_value WHERE column_name = some_value as i am updating the row with a variable name which stores the path to an image would the update still work if the new and old values have the same variable name. Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-545575 Share on other sites More sharing options...
kev wood Posted May 20, 2008 Author Share Posted May 20, 2008 would this code be correct $query = "UPDATE broad_images SET broad2 = $broad2name2 WHERE broad2 = $broad2name2"; mysql_query($query); $broad2name2 is the variable that holds the path to the image. if a new image is uploaded it is stored in the variable, is it possible to update the table if the variable names are the same nut hold different values. Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-545601 Share on other sites More sharing options...
roopurt18 Posted May 20, 2008 Share Posted May 20, 2008 Your question doesn't make any sense and your code is "useless." $query = "UPDATE broad_images SET broad2 = $broad2name2 WHERE broad2 = $broad2name2"; Let's set $broad2name2 equal to 'A' and see what happens. UPDATE broad_images SET broad2 = 'A' WHERE broad2 = 'A' Or, in English, set the column equal to 'A' where the column already equals 'A'. If it already equals 'A', then why bother setting it to 'A'? MySQL will only update the row if the new values are actually different than what currently exists. So in this case, the query would fail because it didn't actually update anything (although semantically it's successful because the column contains the value we wanted). Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-545959 Share on other sites More sharing options...
kev wood Posted May 21, 2008 Author Share Posted May 21, 2008 the variable $broad2name2 would hold a different image each time it was trying to update the mysql table. my question was would it update the table from the same variable name if it held a different value. ie first upload the var = thumb/thumbs_image1.gif second upload the var = thumb/thumbs_image1.png as the images are always stored in this variable for the upload i need to know if i can update the table with the newly uploaded image. Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-546517 Share on other sites More sharing options...
roopurt18 Posted May 21, 2008 Share Posted May 21, 2008 if a new image is uploaded it is stored in the variable, is it possible to update the table if the variable names are the same nut hold different values. You can't have two variables in the same scope with the same name and different values. If you use the variable name $xyz within the same scope, multiple times, each one refers to the same variable. My original point still stands. This does utterly nothing: UPDATE `some_table` SET `col`='Val' WHERE `col`='Val' You need to have a query that looks like: UPDATE `some_table` SET `col`= $NewVal WHERE `col` = $OldVal Link to comment https://forums.phpfreaks.com/topic/106439-truncate-question/#findComment-546581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.