cut a long story short I have 2 tables, one called orders_total and another called orders_complete.

the total_oders table contains rows of what the customer has ordered to eat i.e.

colum called 'item' contains the item description
colum called 'cost' contains the item cost
for example
i can sucessfully display the below using where statement

12 inch pinnaple pizza
9 inch pizza £8
half pound burger £3.40

$result7 = mysql_query("SELECT * from order_total");
while($row = mysql_fetch_array($result7)) 
{ 
$totalitem = $row['item'];
$totalcost = $row['cost'];
$t = $totalitem.' '.$totalcost.', ';
}

basically i need the data transfering from total_orders into a colum called ord_descr in table orders_complete

my 1st query would be to select * from total_orders then using the mysql_fetch_array with the where statement resturns sucessfully the data from total_orders. but when I try to insert the data into colum item in the orders_complete table it only seems to be displaying the last line i.e. half pound burger 3.40 and not all the information.

$result7 = mysql_query("SELECT * from order_total");
while($row = mysql_fetch_array($result7)) 
{ 
$totalitem = $row['item'];
$totalcost = $row['cost'];
$t = $totalitem.' '.$totalcost.', ';
}

mysql_query("UPDATE orders_complete SET ord_descr='$t' WHERE date='06/11/08' and time='13:33:53'") 
or die(mysql_error());

If you are inserting a new row into the table, then you want to use the Insert not Update, take a look at this

i have changed the above code to the following:

include("config.php");

$result7 = mysql_query("SELECT * from order_total");
while($row = mysql_fetch_array($result7)) 
{
$test = array($row['item'].' '.$row['cost'].',');
foreach($test as $value) {
//$arr = array($value[0].$value[1].',');

}
echo $value;
mysql_query("UPDATE orders_complete SET ord_descr='$value' WHERE date='06/11/08' and time='13:33:53'") 
or die(mysql_error());
}

I am trying to send an array to insert into the orders_complete table from a select mysql query to view all rows in total_orders table

all what happens is that the last piece of information is entering into the orders_complete table i.e. half pound burger £3.40 and not the full information from the select * from total_orders table

you are going to have to loop through the array returned from the first query and build an insert query.

can you post the layout of the two tables?

Sure as requested

ORDER_TOTAL Table layout
create table order_total (
ord_id int not null auto_increment,
PRIMARY KEY(ord_id),
item varchar(255),
cost float(6,2));

ORDERS_COMPLETE TABLE
create table orders_complete(
ord_id int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ord_id),
tel varchar(11),
ord_descr mediumtext,
date varchar(10),
time varchar(10),
exc_vat float(4,2),
vat float (4,2),
inc_vat float(4,2));

here is a problem i see. to make transffering an instance (row) in one table to another easier, the tables need to have the same setup.

can you explain everything you are trying to do, because i feel that this step is unnecessary. there might be an easier solution.

oh right ok. well i am in the middle of designing a web based internal ordering system for a local pizza delivery company. basically the orders_complete table holds all processed information about the customer. The total_orders table is a temporary table which is used for when the end user clicks on buttons adding specific food. there is also other tables such as pizzas, kebabs and so on. So finanly when the casheer clicks on PAY button all the information is copyed from the orders_total as well as additional information such as time.

Ok I guess if this isnt going to work then there could be another solution. I have created a form from the select * from total_orders which dispays all data. buttons PAY >>> Cancel and Update and Remove Item (which doesnt work :o( )

The data showing the form could I display the description as

<input type="text" value="$row[' ord_descr']" name="description">

then when the PAY>>> button is clicked the data will be passed using $_POST which a variable of for example

$item = $row['ord_descr'];

but i think as each row will have the same input name as:

<input type="text" value="$row[' ord_descr']" name="description">

I dont think this will update orders_complete table fully and will again only display the last piece of information

each row entry for total_orders needs to be added to 1 field entry in table orders_complete colum ord_descr

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.