Jump to content

truncate question


kev wood

Recommended Posts

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

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

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

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

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