Jump to content

A little help


40esp

Recommended Posts

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

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

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.