943,515 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1213
  • PHP RSS
Nov 6th, 2008
0

converting array from mysql database into a different mysql table

Expand Post »
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

php Syntax (Toggle Plain Text)
  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.

php Syntax (Toggle Plain Text)
  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());
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Nov 6th, 2008
0

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

If you are inserting a new row into the table, then you want to use the Insert not Update, take a look at this
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Nov 6th, 2008
0

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

i have changed the above code to the following:

php Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Nov 6th, 2008
0

Re: converting array from mysql database into a different mysql 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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Nov 6th, 2008
0

Re: converting array from mysql database into a different mysql 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?
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 6th, 2008
0

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

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));
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Nov 6th, 2008
0

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

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 6th, 2008
0

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

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
html Syntax (Toggle Plain Text)
  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
php Syntax (Toggle Plain Text)
  1. $item = $row['ord_descr'];
but i think as each row will have the same input name as:

html Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Nov 6th, 2008
0

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

each row entry for total_orders needs to be added to 1 field entry in table orders_complete colum ord_descr
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Back URL function and keeping search criteria - From Natasha
Next Thread in PHP Forum Timeline: Need to match product with letters before the dash "-"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC