Jump to content

FOREACH and UPDATING


Xtremer360

Recommended Posts

Okay lets say after the form submission I have this inside the post parameters.

 

answersList    Undisputed Title2:::5,Outlaw Title3:::6,Tag Team Titles4:::7

 

If you see I have it exploding the list at the "," character.  Then what I want to happen is for it to take out the ":::" characters and create a variable called $answerID for the number after the ":::" and then have it be able to run through the UPDATE query so that it UPDATES the old value with the new value.

 

$answer = explode(',', $_POST['answersList']);
foreach ($answer as $answer) { 
            
            $answer = htmlspecialchars($answer);
            echo $answer;

            $query = "UPDATE `pollAnswers` 
                    SET `answer` = '".$answer."' WHERE `ID` = '".$answerID."'";
            mysqli_query($dbc, $query);
            echo $query;
        }

Link to comment
https://forums.phpfreaks.com/topic/236149-foreach-and-updating/
Share on other sites

Granted I appreciate the response. I'm not developed enough with regex to use in in my code. I know it'd be easy enough to just put it in but I'd rather not put in anything I don't understand to just to use it.

 

The only thing is when it explodes with the answer I need it to be able to create a variable with what was on teh left as the answer and the right is the answerID. And not sure what step I need to take now.

 

$answer = explode(',', $_POST['answersList']); 
foreach ($answer as $answer) {  
     $answerResult = explode(':::', $_POST['answer']); 
} 

Again I revert back to my first post with what I'm wanting to do.

 

If you see I have it exploding the list at the "," character.  Then what I want to happen is for it to take out the ":::" characters and create a variable called $answerID for the number after the ":::" and then have it be able to run through the UPDATE query so that it UPDATES the old value with the new value.

 

Archived

This topic is now archived and is closed to further replies.

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