40esp Posted June 10, 2008 Share Posted June 10, 2008 I have this code: <?php foreach($update as $update_key=>$update_title){ "\$_POST['select$update_key'] ";} ?> and what im trying to achieve is to combine an array of values into post variables like so: Array 1 2 3 Here is the array code: <?php do { $newsletter[$row_practice_groups['group_id']] = $row_practice_groups['group_name']; $update[$row_practice_groups['group_id']] = $row_practice_groups['group_name']; } while ($row_practice_groups = mysql_fetch_assoc($practice_groups)); ?> This in turn generates a new checkbox for every value in the array for example checkbox one would be called: select1 based on the array variables. here is the code to generate the checkboxes: <?php $is_subscribed = $row_email_record['practice_groups']; foreach($newsletter as $key=>$title) { if (strstr($is_subscribed, "[$key]")) echo "<input type=\"checkbox\" name=\"select$key\" id=\"select\" value=\"[$key]\" checked=\"checked\"/> $title<br />"; else echo "<input type=\"checkbox\" name=\"select\" id=\"select\" value=\"[$key]\"/> $title<br />"; } ?> A user can check these, and it will update their record in the database. well I've run into the bump where I need to combine like so in my sql: "UPDATE newsletters SET practice_groups='$_POST['select1'] && $_POST['select2'] && $_POST['select3']..etc' WHERE id='$_GET['id']'" and im trying to make the first posted code automatically generate the post variables in the update sql statement, that way when the sql is executed, it will combine all of my data. Any ideas? I hope I explained it well. Link to comment https://forums.phpfreaks.com/topic/109495-a-little-help/ Share on other sites More sharing options...
agoeza Posted June 10, 2008 Share Posted June 10, 2008 mm ... have u tried to use implode() function to combine your array values into a string ? see http://www.php.net/implode but i'm wondering, why u named each checkbox with 'checkbox1','checkbox2',etc instead of 'checkbox[]' ? i think it would be better and easier to generate your query later Link to comment https://forums.phpfreaks.com/topic/109495-a-little-help/#findComment-561676 Share on other sites More sharing options...
40esp Posted June 10, 2008 Author Share Posted June 10, 2008 I can do that, thats not a problem. If it was like that, what would I do? also, I looked at implode, but I believe I have a different type of array than what can be used? Link to comment https://forums.phpfreaks.com/topic/109495-a-little-help/#findComment-561678 Share on other sites More sharing options...
40esp Posted June 10, 2008 Author Share Posted June 10, 2008 Anyone? please? Link to comment https://forums.phpfreaks.com/topic/109495-a-little-help/#findComment-561696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.