Jump to content

php help with concatenation into a variable


MidOhioIT

Recommended Posts

What I am trying to do is take x amount of records coming back from the database where "x" is unknown.  Capture that number by looping through and each time it loops through the count, make a new instance of a variable so that it will not be over written.  I need to save each record as it is being used as a new row on a table.  Here is my code:

 

$result = mysql_query("SELECT * FROM invoiceItems where invoiceID = '$invoiceid' ",$db);
$numrows = mysql_num_rows($result);
$tableCounter = $numrows;
$row = 'row';
while ($row = mysql_fetch_array($result)) 
{
$invoiceItem = $row["Item"];
$invoiceDescription = $row["description"];
    $invoiceItemPrice = $row["itemPrice"];

$tableItems ="
    <tr>
          <td width='10'> </td>
          <td width='271'><div align='left'>$invoiceDescription</div></td>
          <td><div align='center'>355</div></td>
          <td width='94'><div align='right'>$</div></td>
          <td width='74'><div align='left'>$invoiceItemPrice</div></td>
        </tr>";

	while ( $tableCounter >= 1 ) 
	{
	  $row.$tableCounter = $tableItems;
          $tableCounter = $tableCounter - 1;
	}

	$alltableItems = $row1.$row2.$row3.$row4;	

}

 

Please help and thanks in advance

I presume by overwritten you mean the $tableItems variable? If so use  this

 

result = mysql_query("SELECT * FROM invoiceItems where invoiceID = '$invoiceid' ",$db);
$numrows = mysql_num_rows($result);
$tableItems = null;
$row = 'row';
while ($row = mysql_fetch_array($result)) 
{
    $invoiceItem = $row["Item"];
    $invoiceDescription = $row["description"];
    $invoiceItemPrice = $row["itemPrice"];

    $tableItems .="
    <tr>
          <td width='10'> </td>
          <td width='271'><div align='left'>$invoiceDescription</div></td>
          <td><div align='center'>355</div></td>
          <td width='94'><div align='right'>$</div></td>
          <td width='74'><div align='left'>$invoiceItemPrice</div></td>
        </tr>";
}

echo $tableItems;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.