I need a simple solution

I have invoice that i want to always diplay 10 rows, but if there is data in mysql it must first put those rows with data in on the invoice then subtract the number of rows and the difference will be the blank rows it must add at the end.

<?php

$totala ="0";
$numrows ="10";

//QUERY
$extract = mysql_query("SELECT * FROM invoicedata WHERE invnum='$invnumber'");

//FIND DATA AND ASSIGN
while ($row = mysql_fetch_assoc($extract))
{
$items = $row['item_description'];
$prices = $row['item_price'];
$quant = $row['item_quantity'];
$itemvat = $row['item_vat'];

$subanswer = $prices * $quant;
$totala = $totala + $subanswer;

$prices = number_format($totala,2);
$subtot = number_format($subanswer,2);

$invtotal = number_format($totala,2);

echo "<table width=833 height=22 cellpadding=0 cellspacing=0>
  <tr bgcolor=#FFFFFF>
    <td width=325><span class=style15>$items</span></td>
    <td width=122><div align=center class=style15>$prices</div></td>
    <td width=107><div align=center class=style15>$quant</div></td>
    <td width=139><div align=center class=style15>$vat</div></td>
    <td width=122><div align=right class=style15>$subtot</div></td>
    <td width=16><div align=right><span class=style15></span></div></td>
  </tr>
</table>";

//$numrows = $numrows - 1

}

//INSERT BLANK LINES

//do until $numrows=0
//echo "<br>";

?>

make only two changes as shown below

<?php
.
.
.
.
while ($row = mysql_fetch_assoc($extract) || $totala<10)
{

$totala++;
.
.
.
.

?>

so final code is:

<?php

$totala ="0";
$numrows ="10";

//QUERY
$extract = mysql_query("SELECT * FROM invoicedata WHERE invnum='$invnumber' limit 0,10");

//FIND DATA AND ASSIGN
while ($row = mysql_fetch_assoc($extract))
{
$items = $row['item_description'];
$prices = $row['item_price'];
$quant = $row['item_quantity'];
$itemvat = $row['item_vat'];

$subanswer = $prices * $quant;
$totala = $totala + $subanswer;

$prices = number_format($totala,2);
$subtot = number_format($subanswer,2);

$invtotal = number_format($totala,2);

echo "<table width=833 height=22 cellpadding=0 cellspacing=0>
  <tr bgcolor=#FFFFFF>
    <td width=325><span class=style15>$items</span></td>
    <td width=122><div align=center class=style15>$prices</div></td>
    <td width=107><div align=center class=style15>$quant</div></td>
    <td width=139><div align=center class=style15>$vat</div></td>
    <td width=122><div align=right class=style15>$subtot</div></td>
    <td width=16><div align=right><span class=style15></span></div></td>
  </tr>
</table>";

$numrows = $numrows - 1;

}

//INSERT BLANK LINES
while($numrows != 0)
{
	echo "<br>";
	$numrows = $numrows - 1;
}

?>

thank you - dont know why ia was trying a while loop - ps: DONT LAUGH I AM NEW AT THIS STUFF

$numrows = $numrows - 1

}

$a = 10;
$a = $a - $numrows;

do
{

echo $a. '<br />';
$a++;

} while ($a <=10);

yours was perfect though, i see what you did :) thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.