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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:47:51+00:00 2026-06-14T11:47:51+00:00

How can i generate a numbers to the table that has been fetch a

  • 0

How can i generate a numbers to the table that has been fetch a data from database, here are my situation:

//Action File Calling a data

$loads = array();
$loadno = $_GET['eig'];
$result = mysql_query("SELECT * FROM task_load WHERE load_no='$loadno' ORDER BY inv ASC");

while($row = mysql_fetch_assoc($result))
{
    $loads[] = new VerifyLoads($row);
}
        foreach($loads as $c){
             echo $c->markup_print();
        }

// Class file receive request

    public function markup_print()
    {
    $d = &$this->data;

    return '
        <tr id="line-'.$d['id'].'">
            <td class="iprint">'.GENERATE_NUMBER_HERE.'</td>
            <td class="cprint">'.$d['customer_name'].'</td>
            <td class="cprint">'.$d['inv'].'</td>
            <td class="rprint">'.$d['value'].'</td>
            <td class="cprint">'.$d['ctn'].'</td>
            <td class="iprint"></td>
            <td class="iprint"></td>
            <td class="iprint"></td>
        </tr>       
        ';
    }
  • 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-06-14T11:47:52+00:00Added an answer on June 14, 2026 at 11:47 am

    Though I am fairly unsure as to what kind of number you’re looking to generate, based on your output I’m assuming you want a simple line-number for the current record that’s being displayed. The difficulty, in this case, is because each line is a separate instance of the VerifyLoads class.

    To handle this you could take one of several ways. The quickest and easiest method will work because you display them in the order you created them. This method will involve two new variables in the VerifyLoads class; the first is a static variable to keep the total-line count and the second is a non-static variable to keep the current instance’s count:

    class VerifyLoads {
        private $_lineTotal = 1;
        private $_lineNumber = -1;
    
        public function __construct() {
            $this->_lineNumber = self::$_lineTotal++;
        }
    
        public function markup_print() {
            $d = &$this->data;
    
            return '
                <tr id="line-'.$d['id'].'">
                <td class="iprint">'.$this->_lineNumber.'</td>
                <td class="cprint">'.$d['customer_name'].'</td>
                <td class="cprint">'.$d['inv'].'</td>
                <td class="rprint">'.$d['value'].'</td>
                <td class="cprint">'.$d['ctn'].'</td>
                <td class="iprint"></td>
                <td class="iprint"></td>
                <td class="iprint"></td>
                </tr>       
            ';
        }
    }
    

    An alternative method, if you didn’t display the records in the same order you created them would be to also keep a static variable in the class but to have a local method that returned the current line:

    class VerifyLoads {
        private static $_lineNumber = 1;
    
        private function _currentLine() {
            return self::$_lineNumber++;
        }
    
        // .. code as normal ..
        // .. to access, just call $this->_currentLine()
    }
    

    If you need to use the second method and also use it to display multiple tables on the same page you could implement a resetLineNumber() method to set the static variable back to 1 as well.

    On the flip-side, I may have completely misunderstood your question. If this is the case, please elaborate as-to-what kind of number you need displayed and I’ll revise.

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

Sidebar

Related Questions

In Haskell, how can I generate Fibonacci numbers based on the property that the
I want to generate random numbers from -n to n excluding 0. Can someone
i want to generate a unique number from a table. It has to be
I use auto generated Entity-Framework Data Model for a Database that has 100+ tables.
Does anybody know if the CUDA library 'Thrust' can generate random numbers on the
How can I generate the sequence of numbers 1,2,5,6,9,10...... and so until 100 in
How can i generate a sequence of numbers which are in Geometric Progression in
How can I generate some unique random numbers between 1 and 100 using JavaScript?
Can you tell me any ways to generate non-uniform random numbers? I am using
I want to generate unique random, N-valued key. This key can contain numbers and

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.