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>
';
}
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
VerifyLoadsclass.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
VerifyLoadsclass; 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: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:
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 to1as 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.