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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.