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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:37:03+00:00 2026-05-28T18:37:03+00:00

Short Generating table with barcodes of items. Each item has exact quantity in database

  • 0

Short

Generating table with barcodes of items. Each item has exact quantity in database table. Fields in tables are limited: 65, if more then 65 then build a second table, then a third one…How to generate tables with this conditions?

enter image description here

Detailed

Let’s say we want to generate a table with 65 available fields (5×13).

My plan is the following

  1. User selects items’ checkboxes
  2. When user submits form, PHP gets values of checked checkboxes
  3. PHP gets quantities of each item from database
  4. Generating table

For ex. the quantity for item id 55 is 2 and for 56 is 4 then the table must look like that

enter image description here

My code looks like that (I know that it’s wrong, but I can’t figure out how it must be. There must be more than 5 counters: rows counter, columns counter, $_POST[‘id’] counter, items’ quantity counter, table counter (if total sum is more than 65))

UPDATE

    <?php
            $items = array();
            foreach ($_POST['checkbox'] as $id) {
                $stmt = $db->prepare("SELECT `qt` FROM `items` WHERE `id`=?");
                $stmt->bind_param('i', $id);
                $stmt->execute();
                $stmt->bind_result($qt);
                $stmt->fetch();
                $stmt->close();
                for ($cnt = 1; $cnt <= $qt; $cnt++)
                    $items[] = $id;
            }
            $i = 0;
            foreach ($items as $item) {
                for ($j = 0; $j < $item['quantity']; $j++) {

                    // check if it's the beginning of a new table
                    if ($i % 65 == 0)
                        echo '<table>';

                    // check if it's the beginning of a new row
                    if ($i % 5 == 0)
                        echo '<tr>';

                    echo '<td><img src="bc.php?id=' . $item['id'] . '" alt="' . $item['name'] . '" /></td>';

                    // check if it's the end of a row
                    if (($i - 1) % 5 == 0)
                        echo '</tr>';

                    // check if it's the end of a table
                    if (($i - 1) % 65 == 0)
                        echo '</tr></table>';

                    $i++;
                }
            }

// if the last row wasn't closed, close it
            if ($i % 5 != 0)
                echo '</tr>';

// if the last table wasn't closed, close it
            if ($i % 65 != 0)
                echo '</table>';
            ?>

Any suggestion?

  • 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-28T18:37:04+00:00Added an answer on May 28, 2026 at 6:37 pm

    EDIT 4

    <?php
    
    $i = 0;
    foreach ($_POST['checkbox'] as $id) {
        $stmt = $db->prepare("SELECT `qt` FROM `items` WHERE `id`=?");
        $stmt->bind_param('i', $id);
        $stmt->execute();
        $stmt->bind_result($qt);
        $stmt->fetch();
        $stmt->close();
    
        for ($cnt = 1; $cnt <= $qt; $cnt++) {
            // check if it's the beginning of a new table
            if ($i % 65 == 0)
                echo '<table>';
    
            // check if it's the beginning of a new row
            if ($i % 5 == 0)
                echo '<tr>';
    
            echo sprintf('<td><img src="bc.php?id=%1$d" alt="%1$d" /></td>', $id);
    
            // check if it's the end of a row
            if (($i + 1) % 5 == 0)
                echo '</tr>';
    
            // check if it's the end of a table
            if (($i + 1) % 65 == 0)
                echo '</table>';
    
            $i++;
        }
    }
    
    // if the last table isn't full, print the remaining cells
    if ($i % 65 != 0) {
        for ($j = $i%65; $j < 65; $j++) {
            if ($j % 65 == 0) echo '<table>';
            if ($j %  5 == 0) echo '<tr>';
            echo '<td></td>';
            if (($j + 1) %  5 == 0) echo '</tr>';
            if (($j + 1) % 65 == 0) echo '</table>';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a largish table of data pulled from my database (~1500 rows, each
Short of inserting a try/catch block in each worker thread method, is there a
Short of rolling your own. There has to be something out there. FlexLM/FlexNet is
I have table called Direccion other called Cliente each one defined like this public
Table has surrogate primary key generated from sequence. Unfortunately, this sequence is used for
I have a table in HTML which I am generating from XML/XSL and I
I am pre-generating short codes for a service I am building that shortens links.
I am generating an HTML table with PHP (using the codeigniter framework) and I'm
I have a database table that essentially contains different types of things. I'll use
As you might have guessed, this is for generating short URLs. What's the best

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.