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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.