Please support our PHP advertiser: Lunarpages PHP Web Hosting
![]() |
•
•
•
•
| |
Hi, I'm creating an administration area for a little web-app and I've come across a problem that I've never encountered before.
The form that I'm working on is used for the maintenance of a table that has several properties. One of these properties can be selected with checkboxes, and then recorded in the correct column in a comma-delimited list. The problem that I'm having is constructing/alterring the list - for some reason I can't for the life of me figure out how to do it.
Oh yeah, the fun part is that the properties that are in the checkbox are created on the fly from another table, which is why i didn't decide to create a column for each option and flag it.
Here's the snippet of code that creates the checkbox area:
[php]
<?php
$sql2 = "SELECT * FROM tbl_action";
$result = mysql_query($sql2);
while($act_row = mysql_fetch_array($result)) {
echo "<input type=checkbox value=\"".$act_row['action_id']."\"> ";
if(strstr($myrow['spy_action'], $act_row['action_id']))
echo "checked>";
echo ucwords($act_row['action_name'])."<br>";
}
?>
[/php]
Ok, 2 tables - spy and action. All columns from spy are called spy_name, and from action are act_name.
So far I've considered using Javascript, making the code create a new column every time a new action is created, and various other techniques that have been thrown out as soon as I think of them.
This is the last part of the admin area, and once it's complete I'll be a very happy boy.
The form that I'm working on is used for the maintenance of a table that has several properties. One of these properties can be selected with checkboxes, and then recorded in the correct column in a comma-delimited list. The problem that I'm having is constructing/alterring the list - for some reason I can't for the life of me figure out how to do it.
Oh yeah, the fun part is that the properties that are in the checkbox are created on the fly from another table, which is why i didn't decide to create a column for each option and flag it.
Here's the snippet of code that creates the checkbox area:
[php]
<?php
$sql2 = "SELECT * FROM tbl_action";
$result = mysql_query($sql2);
while($act_row = mysql_fetch_array($result)) {
echo "<input type=checkbox value=\"".$act_row['action_id']."\"> ";
if(strstr($myrow['spy_action'], $act_row['action_id']))
echo "checked>";
echo ucwords($act_row['action_name'])."<br>";
}
?>
[/php]
Ok, 2 tables - spy and action. All columns from spy are called spy_name, and from action are act_name.
So far I've considered using Javascript, making the code create a new column every time a new action is created, and various other techniques that have been thrown out as soon as I think of them.
This is the last part of the admin area, and once it's complete I'll be a very happy boy.
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
I don't think I understand you correctly. All you want to do is check multiple checkboxes, put those checked values in a comma delimited string, and insert it in some table?
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
Hi inscissor, thanks for the reply. Let me see if I can clarify myself.
I want to be able to check/uncheck multiple checkboxes, and put those values in a comma delimited string, and then stick it in a column, that's right.
The part that's throwing me for a loop though is that the checkboxes are created from the database (the options come from another table) in the first place.
I'm starting to think I'm overthinking this whole problem, but still haven't figured out how to do it.
I want to be able to check/uncheck multiple checkboxes, and put those values in a comma delimited string, and then stick it in a column, that's right.
The part that's throwing me for a loop though is that the checkboxes are created from the database (the options come from another table) in the first place.
I'm starting to think I'm overthinking this whole problem, but still haven't figured out how to do it.
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
Well, your problem seems to stem from how you're creating the checkboxes in the loop. First of all, here:
you don't create a name for the checkbox, so how are you going to retrieve it? The way it's usually done is you give the checkbox a name with open and closed bracks, like this: values[]
So when you pass this over, it'll pass it over as an array. So this is all you have to do:
So when you submit this, it'll submit an array of the values of only the ones that got checked. So you loop through this array, in this case being values[]. Also, when you're retrieving this form variable, retrieve it as $_POST['values'] and not $_POST['values[]']. I'm sure you can do the rest. Anything else, let me know.
•
•
•
•
Originally Posted by SEO Bob
[php]
echo "<input type=checkbox value=\"".$act_row['action_id']."\"> ";
[/php]
So when you pass this over, it'll pass it over as an array. So this is all you have to do:
•
•
•
•
Originally Posted by SEO Bob
[php]
<?php
$sql2 = "SELECT * FROM tbl_action";
$result = mysql_query($sql2);
while($act_row = mysql_fetch_array($result)) {
echo "<input type=checkbox name="values[]" value=\"".$act_row['action_id']."\"> ";
if(strstr($myrow['spy_action'], $act_row['action_id']))
echo "checked>";
echo ucwords($act_row['action_name'])."<br>";
}
?>
[/php]
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
•
•
•
•
Originally Posted by SEO Bob
Thanks Inscissor,
To be honest, I don't do much work with forms, which is why I wasn't sure how to handle this. I really appreciate the help, though.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
•
•
•
•
Originally Posted by SEO Bob
Given that the data is stored in an array, what type of structure should I use for storing it?
[php]
$values = $_POST['value']; // getting value array from form variable
$delimited_values = implode(",", $values);
echo $delimited_values;
[/php]
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
It actually doesn't matter if they're stored in a comma-delimited string or not (but yes, i did say that that's how i wanted it).
My only requirement is that the data can be retrieved and written to easily. I've been looking at serializing the array and putting it into the column, but if you have another recommendation...
My only requirement is that the data can be retrieved and written to easily. I've been looking at serializing the array and putting it into the column, but if you have another recommendation...
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
That sounds fine. Maintaining it as an array gives you a lot of flexivity. You can manipulate it easily with the PHP array functions.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
![]() |
Similar Threads
Other Threads in the PHP Forum
- Forms in Random access files (Visual Basic 4 / 5 / 6)
- HOWTO: Share an SQL Connection between multiple forms within the same project (C#)
- Hotmail and Submitting Forms (Web Browsers)
- PLEASE, I need help with this....why can't I get it to work? (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: making own webmail
- Next Thread: Error getting forms to send information
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Hybrid Mode