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

  • SEARCH
  • Home
  • 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 6188455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:14:04+00:00 2026-05-24T02:14:04+00:00

I’m trying to build a simple HTML table form that displays values from a

  • 0

I’m trying to build a simple HTML table form that displays values from a PHP array. The display part is easy, but I forget how to code form mechanics like selecting and deletion of these values based on user input. I figured they may be an example of something similar online, but have not found anything suitable so far. I am interested in some simple code that allows a user to delete single or multiple lines from a HTML table. I would like to avoid JavaScript or jQuery if possible.

Here is what I have so far:

HTML/ PHP

<form action="options.php" method="post">
<table>
<thead>
    <tr>
        <th><input type="checkbox"></th>
        <th>Domain Name</th>
    </tr>
</thead>
<tfoot>
    <tr>
        <th><input type="checkbox"></th>
        <th>Domain Name</th>
    </tr>
</tfoot>
<tbody>
    <?php
        foreach ( $my_domains as &$value ) {
            echo '<tr><td><input type="checkbox"></td><td>'.$value['domain'].'</td></tr>';
        }
    ?>
</tbody>
</table>
</form>

PHP ARRAY

Array ( [10] => Array ( [domain] => dsdssd.com ) [11] => Array ( [domain] => google.com ) [12] => Array ( [domain] => new.com ) [13] => Array ( [domain] => blah.com ) )
  • 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-24T02:14:06+00:00Added an answer on May 24, 2026 at 2:14 am

    So.. In a nutshell. This is what you asked for.. Anyways, you add more options in the form on checkboxex, like which domains are active and so on.. Still, if I was you, I would make this in jQuery and with ajax. Would be much more neater.

    Example: http://kopli.pri.ee/stackoverflow/6829783.php

    NOTE There is no memory. So if basically reload the page in any way, some parts will be reseted.

    EDIT

    This one has the delete all function. It actually uses php fallback aswell as jQuery script to select all. Not sure if its the ultimate way of doing things, so you might want to remove the php fallback option, if your going to use jQuery select all.

    Example 2: http://kopli.pri.ee/stackoverflow/6829783_v2.php

    (This is the updated code below)

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <?php
    $my_domains[1]['domain'] = 'dsdssd.com';
    $my_domains[2]['domain'] = 'google.com';
    $my_domains[3]['domain'] = 'new.com';
    $my_domains[4]['domain'] = 'blah.com';
    $my_domains[5]['domain'] = 'kopli.pri.ee';
    $my_domains[6]['domain'] = 'iyfgaming.com';
    
    if ($_POST['trigger']) {
        $p_delete_all = $_POST['delete_all'];
        $p_ids = $_POST['ids']; # Get IDs
        $p_deletes = $_POST['deletes']; # Get deletes
        if ($p_delete_all) {
            unset($my_domains);
        } elseif (is_array($p_ids)) {
            foreach ($p_ids as $id) {
                if ($p_deletes[$id]) {
                    unset($my_domains[$id]);
                }
            }
        }
    }
    
    ?>
    
    <form action="" method="post">
    <input type="hidden" name="trigger" value="1">
    <table>
    <thead>
        <tr>
            <th><input type="checkbox" name="delete_all" value="1"></th>
            <th>Domain Name</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th><input type="checkbox" name="delete_all" value="1"></th>
            <th>Domain Name</th>
        </tr>
    </tfoot>
    <tbody>
        <?php
            if (is_array($my_domains)) {
                foreach ( $my_domains as $array_id => $value ) {
                    echo '<input name="ids[]" type="hidden" value="' . $array_id . '">' . "\n";
                    echo '<tr><td><input name="deletes[' . $array_id . ']" value="1" type="checkbox"></td><td>'. $value['domain'] . '</td></tr>' . "\n\n";
                }
            } else {
                echo '<tr><td colspan="2">Nothing to display :(</td></tr>';
            }
        ?>
    </tbody>
    </table>
    <br>
    <input type="submit" value="Update">
    </form>
    
    <script>
    $('input[name=delete_all]').click(function () {
        if ($(this).is(':checked')) {
            $('tbody input[type=checkbox]').each(function () {
                $(this).attr('checked', true);
            });
            $('input[name=delete_all]').attr('checked', true);
        } else {
            $('tbody input[type=checkbox]').each(function () {
                $(this).attr('checked', false);
            });
            $('input[name=delete_all]').attr('checked', false);
        }
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.