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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:27:26+00:00 2026-05-27T21:27:26+00:00

I have the following PHP function which will list the users from a MySql

  • 0

I have the following PHP function which will list the users from a MySql table and will print the HTML code as you can see:

//List All Users From The Database Table In An Array
public function listUsersInArray() {
    $sql = "SELECT username FROM user";
    $users = array();
    if($stmt = $this->conn->prepare($sql)) {
        $stmt->bind_result($usrn);
        $stmt->execute();

        while ($row = $stmt->fetch()) {
            $stmt->bind_result($usrn);
            $users[] = $usrn;
        }
        $stmt->close();
        return $users;
    }
        else {
            $error = true;
            $message['error'] = true;
            $message['message'] = "The Users Could Not Stored In Array";
            return json_encode($message);       
        }
}

//Build A Form In Order To Print Out The Users For Deleting
private function createForm($id) {
    $form = array(  '<form name="delete-user" id="'.$id.'" class="delete-user" method="post" action="#">',
                        '<input type="hidden" name="user_id" value="'.$id.'" />',
                        '<fieldset class="user-wrapper">',
                            '<label for="user" class="user-label">User</label>',
                            '<input type="text" name="user" class="user" value="'.$id.'" autocomplete="off" readonly="readonly" />',
                        '</fieldset>',
                        '<fieldset class="delete-wrapper">',
                            '<button type="submit" name="delete" class="delete">Delete</button>',
                        '</fieldset>',
                    '</form>' 
            );
    $form = implode("",$form);
    return  $form;                  
}

//List All Users From Array As Forms For Deleting
public function listUsersForDelete() {
    $users = $this->listUsersInArray();     
    for ($i = 0; $i < sizeof($users) ; $i++) {
        while((sizeof($users) <= ($i % 7 == 0 || $i == 0))) {
        echo $this->createForm($users[$i]);
        $i++;
    }
    }   
}

And now I just have to figure out how to add a wrap the all the forms in a div if the forms are more than 7 and do that each time I encounter a multiple of 7.

For example, if I have 9 forms, wrap the first 7 in a div but also wrap the rest in another div, and if I have 16 forms, wrap the first 7 in a div, the next 7 in a div and the rest of 2 in another div, and so on …

  • 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-27T21:27:26+00:00Added an answer on May 27, 2026 at 9:27 pm

    You suggested code looks fine. The only thing I would suggest is that you store the <form> code into a variable first instead of just copying and pasting it. Copying and pasting is prone to a lot of errors, especially if you have to update the code later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code with the following form: <?php function doSomething{ //Do stuff with MySQL
I have the following PHP code which works out the possible combinations from a
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have tried to do this refering to following link. http://skypher.com/index.php/2008/07/28/function-list-for-php/ But no success.
I have the following php code, which has been snipped for brevity. I am
I have my front end script which has the following jQuery code: $.get(/backend/post.php, {
I have the following code, which will not work. The javascript gives no errors
I have the following php function which i wrote a while ago. Now however,
I have a php script to retrieve data from a MysQL databse following an
I have the following php code (getRout.php).. which response results in xml formats ...

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.