| | |
converting array from mysql database into a different mysql table
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
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
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.
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)
$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.
php Syntax (Toggle Plain Text)
$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
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.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
i have changed the above code to the following:
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
php Syntax (Toggle Plain Text)
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
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
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));
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.
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.
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
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
then when the PAY>>> button is clicked the data will be passed using $_POST which a variable of for example but i think as each row will have the same input name as:
I dont think this will update orders_complete table fully and will again only display the last piece of information
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)
<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)
$item = $row['ord_descr'];
html Syntax (Toggle Plain Text)
<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
![]() |
Other Threads in the PHP Forum
- Previous Thread: Back URL function and keeping search criteria - From Natasha
- Next Thread: Need to match product with letters before the dash "-"
| Thread Tools | Search this Thread |
# .htaccess 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm mod_rewrite multiple mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validation validator variable video web xml youtube






