converting array from mysql database into a different mysql table

Reply

Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

converting array from mysql database into a different mysql table

 
0
  #1
Nov 6th, 2008
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

  1. $result7 = mysql_query("SELECT * from order_total");
  2. while($row = mysql_fetch_array($result7))
  3. {
  4. $totalitem = $row['item'];
  5. $totalcost = $row['cost'];
  6. $t = $totalitem.' '.$totalcost.', ';
  7. }


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.

  1. $result7 = mysql_query("SELECT * from order_total");
  2. while($row = mysql_fetch_array($result7))
  3. {
  4. $totalitem = $row['item'];
  5. $totalcost = $row['cost'];
  6. $t = $totalitem.' '.$totalcost.', ';
  7. }
  8.  
  9. mysql_query("UPDATE orders_complete SET ord_descr='$t' WHERE date='06/11/08' and time='13:33:53'")
  10. or die(mysql_error());
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: converting array from mysql database into a different mysql table

 
0
  #2
Nov 6th, 2008
If you are inserting a new row into the table, then you want to use the Insert not Update, take a look at this
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

Re: converting array from mysql database into a different mysql table

 
0
  #3
Nov 6th, 2008
i have changed the above code to the following:

  1. include("config.php");
  2.  
  3. $result7 = mysql_query("SELECT * from order_total");
  4. while($row = mysql_fetch_array($result7))
  5. {
  6. $test = array($row['item'].' '.$row['cost'].',');
  7. foreach($test as $value) {
  8. //$arr = array($value[0].$value[1].',');
  9.  
  10. }
  11. echo $value;
  12. mysql_query("UPDATE orders_complete SET ord_descr='$value' WHERE date='06/11/08' and time='13:33:53'")
  13. or die(mysql_error());
  14. }

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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

Re: converting array from mysql database into a different mysql table

 
0
  #4
Nov 6th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: converting array from mysql database into a different mysql table

 
0
  #5
Nov 6th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

Re: converting array from mysql database into a different mysql table

 
0
  #6
Nov 6th, 2008
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));
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: converting array from mysql database into a different mysql table

 
0
  #7
Nov 6th, 2008
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.
Last edited by kkeith29; Nov 6th, 2008 at 5:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

Re: converting array from mysql database into a different mysql table

 
0
  #8
Nov 6th, 2008
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
  1. <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
  1. $item = $row['ord_descr'];
but i think as each row will have the same input name as:

  1. <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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

Re: converting array from mysql database into a different mysql table

 
0
  #9
Nov 6th, 2008
each row entry for total_orders needs to be added to 1 field entry in table orders_complete colum ord_descr
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC