MidOhioIT Posted August 10, 2008 Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/119044-php-help-with-concatenation-into-a-variable/ Share on other sites More sharing options...
wildteen88 Posted August 10, 2008 Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/119044-php-help-with-concatenation-into-a-variable/#findComment-613011 Share on other sites More sharing options...
MidOhioIT Posted August 10, 2008 Author Share Posted August 10, 2008 THANK YOU that is exactly what I needed. I was having problems getting me concatenation to store in the variable correctly. Much THANKS Link to comment https://forums.phpfreaks.com/topic/119044-php-help-with-concatenation-into-a-variable/#findComment-613021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.