Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6602063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:49:56+00:00 2026-05-25T18:49:56+00:00

A PHP script is generating the following table panel based on the data from

  • 0

A PHP script is generating the following table panel based on the data from a mysql DB. Each cell of the table contains a checkbox which sets the access to some ‘areas’. The name of my checkboxes are following a certain rule: u[user_id]a[area_name] and I was thinking to get all the $_POST’s which are set and to save them in the data base with their values.

The number of the areas are fixed, but the number of the users varies by days. The table in which I have to save the status of the table is: user_id, current_date, area1, area2, area3, area4, area5, .. area25.

The problem is that I don’t know how to save this table into the database. At this moment I do an insert for each user and I think it has to better solution because this takes too much time.

<form name="foo" method="post" action="saveme.php" />    
<table><tr>
    <td>name</td><td>area1</td><td>area2</td><td>area3</td><td>area4</td>
</tr>
<tr>
    <td>John Smith</td>
    <td><input type="checkbox" value="12" name="u1a1" checked /></td>
    <td><input type="checkbox" value="13" name="u1a2" /></td>
    <td><input type="checkbox" value="16" name="u1a3" /></td>
    <td><input type="checkbox" value="21" name="u1a4" checked /></td>
</tr>
</table><input type="submit" value="Save" /> </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:49:57+00:00Added an answer on May 25, 2026 at 6:49 pm

    I think this should do the trick. However, when I see fields like ‘area1, area2, … area25’ – I have a tendency to think there may be a better solution. Perhaps the table should have the fields ‘user_id, current_date, area_id, area’ instead?

    $users = array();
    foreach ($_POST as $key => $value) {
        $matches = null;
        if (preg_match('/^u(\d+)a(\d+)$/', $key, $matches)) {
            $user_id = $matches[1];
            $area_id = $matches[2];
            if (!isset($users[$user_id))) {
                $users[$user_id] = array_fill(1, 25, 0);
            }
            $users[$user_id][$area_id] = mysql_real_escape_string($value);
        }
    }
    $values = array();
    
    foreach ($users as $user_id => $areas) {
        $values[] = '(' . $user_id .', now(), '. implode(', ', $areas) .')';
    }
    
    if ($values) {
        $sql = 'INSERT INTO user_areas (user_id, current_date, area1, area2, area3, area4, area5, area6, area7, area8, area9, area10, area11, area12, area13, area14, area15, area16, area17, area18, area19, area20, area21, area22, area23, area24, area25) VALUES ' . implode(', ', $values);
    
        // execute $sql query
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a PHP script which I'm running from a command line (windows) that
I'm generating an XML document from a PHP script and I need to escape
I've got a php script. Most of the time the script returns html, which
I am trying to write a server side script (PHP) for generating an SVG
Having some trouble sending properly formatted HTML e-mail from a PHP script. I am
How can you run the following script in generating docs by PHPdoc? #1 sudo
I am generating a simple form with php. The following code has been reduced
I am generating a JS navigation using PHP. Script is included like so <script
UPDATE 2: I have now removed the following from the .php file: <?php error_reporting(
I have a php script that is generating an unspecified number of divs inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.