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 604173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:00:35+00:00 2026-05-13T17:00:35+00:00

I have a for loop which actually displays a product name and several buttons

  • 0

I have a for loop which actually displays a product name and several buttons like: Edit, Update , Cancel
For each product i am displaying , it will have its own set of Edir, Update, and Cancel button as below.

Paint Edit Update Cancel

I want to loop through the buttons so that for each category, I can perform a different action. I was thinking about using something like btn_edit1, btn_edit2 for the name of the button and use a for loop. 1, 2 are the category ids.
Maybe Im not clear enough. Sorry for that. Can anyone give me some suggestions?

for($i = 0; $i<count($obj_categories_admin->categories);$i++)
{   

            echo "<tr>";

            echo "<td width='1500'>";
            echo "<input type='text' name='name'  size = '30' value='" . $obj_categories_admin->categories[$i]['name'] . "'/>";

            echo "</td>";

            echo "<td width='500'>";

            echo "<input type='submit' value = 'Update details' name='submit_update_category_" . 
            $obj_categories_admin->categories[$i]['category_id'] . "'/>";

            echo "</td>";



            echo "<td width='500'>";

            echo "<input type='submit' value = 'Edit Sub Categories' name='submit_edit_sub_" . 
            $obj_categories_admin->categories[$i]['category_id'] . "'/>";

            echo "</td>";

            echo "<td width='500'>";
            echo "<input type='submit' value = 'Delete' name='submit_delete_category_" . 
            $obj_categories_admin->categories[$i]['category_id'] . "'/>";
            echo "</td>";

            echo "<td width='500'>";

            echo "<input type='submit' value = 'Cancel' name='cancel'" . "'/>" ;

            echo "</td>";

            echo "</tr>";   
    }

I want to do something like

foreach($_POST as $key => $value)
{

}

so that when i click on a button it performs an action depending on the category_id.

I have tried this as suggested:

echo "<input type='submit' name='submit[add_category]'" . 
"[" . $obj_categories_admin->categories[$i]['category_id'] . "]". " value='Add' />";

Now in my class, i have:

$a1 = $_POST['submit']; 
    $which_action = reset(array_keys($a1)); 
    $which_category = reset(array_keys($a1[$which_action])); 

But, i am getting the error : undefined index submit

  • 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-13T17:00:36+00:00Added an answer on May 13, 2026 at 5:00 pm

    I would give the name attributes of my submit buttons using following pattern:

    name="submit[which_action][which_category]"
    

    For example for your ‘Update’ button for category 123:

    name="submit[update][123]"
    

    When the user clicks any of the submit buttons, to determine which specific button the user has clicked you just need check for $_POST[‘submit’] in your PHP code:

    $a1 = $_POST['submit'];
    $which_action = reset(array_keys($a1));
    $which_category = reset(array_keys($a1[$which_action]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.