Hi I have a fetch all row data from my prices table so it displays all the records on one page using php.

I want to insert all the row data into a new table but in one row.

for example in my 1st table I have PriceID ProductCode Productame ProductAmout which are being displayed i want to add 2 new values to each row and insert all of them in a new table is there any easy way to do this?

at the end of your while loop you can add an insert with your $row and variables.
this will insert every record from the first table adding your 2 extra values

mmm kinda understand but bit confused here is the 1st bit of code i am using.

sorry i am a bit new to this but learning fast.

<table width="100%" cellspacing="0" cellpadding="2" border="0">
<form name="form2" method="post" action="test.php" onsubmit="return v.exec()">
<?
$cid = mysql_real_escape_string($_GET['cid']);
$query = "select * from tblcustomerdetails where intCustomerID = '$cid'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$cid = $row["intCustomerID"];
?>
<tr>
<td><?print_r( $row['vcCCompanyName'])?></td><td align="left">Tel:&nbsp;<?print_r( $row['vcCDPhone'])?></td>
</tr>
<tr>
<td><?print_r( $row['vcCStreetNo'])?>&nbsp;<?print_r( $row['vcCStreet'])?></td><td align="left">Fax:&nbsp;<?print_r( $row['vcCFaxNo'])?></td>
</tr>
<tr>
<td><?print_r( $row['vcCCity'])?></td><td align="left">Email:&nbsp;<?print_r( $row['vcCEmail'])?></td>
</tr>
<tr>
<td><?print_r( $row['vcCState'])?></td><td>&nbsp;</td>
</tr>
<tr>
<td><?print_r( $row['vcCPostalCode'])?></td><td>&nbsp;</td>
</tr>
<tr>
<td><?print_r( $row['vcCCountry'])?></td><td>&nbsp;</td>
</tr>
</table>
<br />
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td>&nbsp;</td><td><b>Code</b></td><td><b>Name</b></td><td><b>Description</b></td><td><b>Price</b></td><td colspan="2" align="center"><b>Action</b></td>
</tr>
<?
$accountsql="select * from tblpricedetails where intCustomerID=$cid order by intProductID asc";
$tempdata=$DB_site->query($accountsql);
$count =$DB_site->num_rows($tempdata); 
while($rowdata=$DB_site->fetch_array($tempdata))
{
$intPriceID = $row["intPriceID"];
$intProductID = $row["intProductID"];
$vcProductCode = $row["vcProductCode"];
$vcProductName = $row["vcProductName"];
$vcProductDescription = $row["vcProductDescription"];

?>
<tr> 
<td class="accountsumb">
<?=$rowdata["intProductID"]?>
</td>
<td class="accountsume">
<?=$rowdata["vcProductCode"]?>
</td>
<td class="accountsumc">
<?=$rowdata["vcProductName"]?>
</td>
<td class="accountsumc">
<?=$rowdata["vcProductDescription"]?>
</td>
<td class="accountsumc">
<?=number_format($rowdata["ftAmount"],2,".",",");?>
</td>
<td class="accountsumc" align="right">
<input type="text" size="10" name="Quantity" />
</td>
<td class="accountsumc" align="center">
<input type="text" size="10" name="total" />
</td>
</tr>
<? 
}
?>
<? if($count==0) 
{ 
?>
<tr bgcolor="#EFEFEF" class="smallblack"> 
<td colspan="7" align="center" bgcolor="#EFEFEF" class="redtext">This user has no product data. </td>
</tr>
<? 
}
?>
<tr>
<td colspan="7" align="center"><br />
<input name="submit" type="submit" class="button" value="Submit" />
</td>
</tr>
<tr>
<td colspan="7" align="center">
<input class="button" type="reset" name="reset" value="Reset" />
</td>
</tr>
</table>
</form>

eveything displays ok its just passing the product values

you can add this at the bottom of your while

$insertdate = mysql_query("INSERT INTO tablename (fields) VALUES(".$row['field'].")") or die(mysql_error());

add your fields in the fields area and your data into the values area.

When i click submit doesn't show any error messages but doesn't write any new rows or data into tblinvoicedetails?? i have m sql conection links in the header of the documet which works ok on every other page with sql commands.

<?PHP
include("checkadminlogin.php");
include("global/connection.php");
$intCustomerID          = stripslashes($_POST["intCustomerID"]);
?>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<form name="form2" method="post" action="index.php" onsubmit="return v.exec()">
<?
$cid = mysql_real_escape_string($_GET['cid']);
$query = "select * from tblcustomerdetails where intCustomerID = '$cid'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$cid = $row["intCustomerID"];
?>
<tr>
<td><?print_r( $row['vcCCompanyName'])?></td><td align="left">Tel:&nbsp;<?print_r( $row['vcCDPhone'])?></td>
</tr>
<tr>
<td><?print_r( $row['vcCStreetNo'])?>&nbsp;<?print_r( $row['vcCStreet'])?></td><td align="left">Fax:&nbsp;<?print_r( $row['vcCFaxNo'])?></td>
</tr>
<tr>
<td><?print_r( $row['vcCCity'])?></td><td align="left">Email:&nbsp;<?print_r( $row['vcCEmail'])?></td>
</tr>
<tr>
<td><?print_r( $row['vcCState'])?></td><td>&nbsp;</td>
</tr>
<tr>
<td><?print_r( $row['vcCPostalCode'])?></td><td>&nbsp;</td>
</tr>
<tr>
<td><?print_r( $row['vcCCountry'])?></td><td>&nbsp;</td>
</tr>
</table>
<br />
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td>&nbsp;</td><td><b>Code</b></td><td><b>Name</b></td><td><b>Description</b></td><td><b>Price</b></td><td colspan="2" align="center"><b>Action</b></td>
</tr>
<?
$accountsql="select * from tblpricedetails where intCustomerID=$cid order by intProductID asc";
$tempdata=$DB_site->query($accountsql);
$count =$DB_site->num_rows($tempdata); 
while($rowdata=$DB_site->fetch_array($tempdata))
{
$intPriceID = $row["intPriceID"];
$intProductID = $row["intProductID"];
$vcProductCode = $row["vcProductCode"];
$vcProductName = $row["vcProductName"];
$vcProductDescription = $row["vcProductDescription"];

?>
<tr> 
<td class="accountsumb">
<?=$rowdata["intProductID"]?>
</td>
<td class="accountsume">
<?=$rowdata["vcProductCode"]?>
</td>
<td class="accountsumc">
<?=$rowdata["vcProductName"]?>
</td>
<td class="accountsumc">
<?=$rowdata["vcProductDescription"]?>
</td>
<td class="accountsumc">
<?=number_format($rowdata["ftAmount"],2,".",",");?>
</td>
<td class="accountsumc" align="right">
<input type="text" size="10" name="Quantity" />
</td>
<td class="accountsumc" align="center">
<input type="text" size="10" name="total" />
</td>
</tr>
<? 
}
?>
<? if($count==0) 
{ 
?>
<tr bgcolor="#EFEFEF" class="smallblack"> 
<td colspan="7" align="center" bgcolor="#EFEFEF" class="redtext">This user has no product data. </td>
</tr>
<? 
$insertdate = mysql_query("INSERT INTO tblinvoicedetails (fields) VALUES(".$row['field'].")") or die(mysql_error());

}

?>

<tr>
<td colspan="7" align="center"><br />
<input name="submit" type="submit" class="button" value="Submit" />
</td>
</tr>
<tr>
<td colspan="7" align="center">
<input class="button" type="reset" name="reset" value="Reset" />
</td>
</tr>
</table>
</form>
This article has been dead for over six months. Start a new discussion instead.