Jump to content

RCurtis

New Members
  • Posts

    7
  • Joined

  • Last visited

RCurtis's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Reversing the quotes did it! I *thought* I had tried that previously but obviously bungled it or did not hit upon that variation. I knew I was close (hoped, anyway!). Many thanks!!
  2. I realize this straddles the line into MySQL...I am hoping someone can show me another way... I have the following code that builds a sql query string: $sql='UPDATE mytable SET user_class = $class_list WHERE user_id = $userid '; When I "echo" it out for troubleshooting it looks right. However...I have a situation where the $class_list string translates to an empty string "". This appears to be throwing MySQL into a syntax error: It seems to think the column I am referencing in the WHERE is the $userid instead of user_id (which IS correct) UPDATE e107_test SET user_class = $class_list WHERE user_id = $userid Could not update class: Unknown column '$userid' in 'where clause' When I do this: $sql='UPDATE mytable SET user_class = "$class_list" WHERE user_id = "$userid" '; This is the echo result - UPDATE mytable SET user_class = "$class_list" WHERE user_id = "$userid" It no longer complains about an Unknown column but it also does not update any records. I have the following to help troubleshoot: $sqlresult = mysql_query( $sql1, $conn ); if(! $sqlresult ) { die('Could not update class: ' . mysql_error()); exit; } else { echo 'Changed 1 record'; echo '<br>'; } //This is the end of the $sql1 query Here is what I get: UPDATE mytable SET user_class = "$class_list" WHERE user_id = "$userid" Changed 1 record I get the "Changed 1 record" output for every record in table but refreshing the table in phpMyAdmin shows that no data has changed. I know I'm doing something stupid.... ??
  3. As I suspected...I am trying to imply a process from other languages/databases. Thanks!
  4. Showing my ignorance again... I have a while loop that steps through every record in a table, looks at a given field and does some manipulations on that one field. I now need to write that single field back. Most all of the examples I've seen take the form of: UPDATE table SET field_data = $new_data WHERE id=1 I may be visualizing what MySQL is doing incorrectly, but using a WHILE loop would seem to me that you are currently "on that record at this moment in time"...can you not just somehow write that new fields' data right then and then allow the loop to continue? Do you really have to deal with a record id & such? (Not sure if I am explaining myself clearly...in other words, I have my new field data ready to do an immediate write but it is ONLY for that certain field...I have not read the entire row.) I know about REPLACE INTO but that seems like overkill given that all I want to do is change one field. Am I looking at this the wrong way?
  5. DavidAM...The explode/implode snippet worked perfectly!! Thank you so much. I had a feeling it was going to involve explode...but I've never used implode before and I certainly don't think I would have ever gotten the entire if statement down on my own...Thanks!
  6. Thanks very much for the quick reply! I wish that I *could* change the database...but it is part of a website CMS that I really can't change. *I* am the one that is (somewhat) going out on a limb and trying to do something behind the scenes.
  7. Very much a noob here...please bear with me! I have a MySQL table that has a particular column that contains data that "looks" like CSV data. Example: We'll say that the column name is "class" record 1 - 1,3,5,2,8,10 record 2 - 6,4,8,10,2,1 I need to read through each record (I know how to do this...) read each field value into a string (can do this...) Here is my challenge: Once I have the data read into a string value I need to be able to "remove" a given value from the string and write it back. In other words, let's assume I want to remove "1": Data would become: record 1 - 3,5,2,8,10 record 2 - 6,4,8,10,2 Note that any of the field values could have a "1" *and* a "10". Simply looking for the "1"s in a string search isn't going to cut it. I am assuming the data needs to be pulled into an array and do some comparing...but my brain is "losing it" here...no clue how to proceed! Can someone point me in a direction?
×
×
  • 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.