Jump to content

[SOLVED] Checkboxes and Arrays


sethkain

Recommended Posts

I have searched for an answer to this and didn't find anything specific to what I am trying to do. Hopefully I am just missing something small.

 

In my db are multiple tables all with the same layout.

They all contain: id, name.

For the 'floor' table it contains (floor_id, floor).

 

I am looping through all the tables with one query statement.

And then displaying each table's data with checkboxes.

On the next page I want to implode the array for each table.

Then store all of them in a separate table.

 

Everything works, except the checkbox name as an array.

I get an error when i do this:

echo"<td><input type='checkbox' name='$tablename[]' value='$tablenameid' />$variablename</td>";

 

But if i change it to this:

echo"<td><input type='checkbox' name='tablename[]' value='$tablenameid' />$variablename</td>";

It works just fine. But then there is just ONE big array called tablename.

 

Link to comment
https://forums.phpfreaks.com/topic/61983-solved-checkboxes-and-arrays/
Share on other sites

ss32 that worked great. I actually tried something similar earlier, but I must have gotten it wrong somehow.

One more issue.

When i try to loop through taking each array and imploding it into a string:

$tables = array("style", "parking", "construction", "foundation");

foreach ($tables as $tablename) {
$tablenamestring= implode(",", $tablename);
echo ($tablenamestring);
}

I get this error message:

Warning: implode() [function.implode]: Bad arguments.

But when i change the code to this:

foreach ($tables as $tablename) {
$tablenamestring= implode(",", $style);
echo ($tablenamestring);
}

it works fine.

when this code executes:

$tables = array("style", "parking", "construction", "foundation");

foreach ($tables as $tablename) {
$tablenamestring= implode(",", $tablename);
echo ($tablenamestring);
}

This line:

$tablenamestring= implode(",", $tablename);

Executes as this:

$tablenamestring= implode(",", style);

Well duh that is why i was getting

Warning: implode() [function.implode]: Bad arguments.

Changed code to:

$tablenamestring= implode(",", $$tablename);

Works fine. Hope this helps someone in the future.

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.