Xtremer360 Posted May 11, 2011 Share Posted May 11, 2011 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; } Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/ Share on other sites More sharing options...
xyph Posted May 11, 2011 Share Posted May 11, 2011 REGEX to the rescue <?php $regex = '/((?:[\w]++ ?+)++)::\d)/'; $subject = 'answersList Undisputed Title2:::5,Outlaw Title3:::6,Tag Team Titles4:::7'; preg_match_all($regex, $subject, $result, PREG_SET_ORDER); print_r($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214160 Share on other sites More sharing options...
Xtremer360 Posted May 11, 2011 Author Share Posted May 11, 2011 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']); } Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214164 Share on other sites More sharing options...
xyph Posted May 11, 2011 Share Posted May 11, 2011 I'll need to see more examples of data this script might be given. Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214173 Share on other sites More sharing options...
Xtremer360 Posted May 11, 2011 Author Share Posted May 11, 2011 Cage Match2:::25,Ladder Match2:::26,Money in the Bank Match:::27,Hair vs. Mask Match:::28,Fans Bring Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214174 Share on other sites More sharing options...
Xtremer360 Posted May 11, 2011 Author Share Posted May 11, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214177 Share on other sites More sharing options...
xyph Posted May 11, 2011 Share Posted May 11, 2011 <?php $d0 = 'Cage Match2:::25,Ladder Match2:::26,Money in the Bank Match:::27,Hair vs. Mask Match:::28,Fans Bring'; $d1 = explode(',',$d0); $d2 = array(); foreach( $d1 as $data1 ) { if( strstr($data1,':::') ) $d2[] = explode(':::',$data1); } print_r($d2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214181 Share on other sites More sharing options...
Xtremer360 Posted May 11, 2011 Author Share Posted May 11, 2011 I'm still confused because I"m not seeing my $answer variable or my $answerID variable like as described in my question. Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214184 Share on other sites More sharing options...
xyph Posted May 11, 2011 Share Posted May 11, 2011 I'm not going to fix code for you. I'm going to show you how you can fix what you've done wrong. If you don't know what my script is doing, ask me about a particular line or loop. Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214186 Share on other sites More sharing options...
Xtremer360 Posted May 11, 2011 Author Share Posted May 11, 2011 Then even bother responding? Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214188 Share on other sites More sharing options...
monkeytooth Posted May 11, 2011 Share Posted May 11, 2011 Tacos? Quote Link to comment https://forums.phpfreaks.com/topic/236149-foreach-and-updating/#findComment-1214193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.