| | |
help in sending php array to 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
Hi All
I was wondering if somebody could help me as this is driving me crazy.
I am trying to send an array from a mysql_fetch_array result to a seporate table. I have the following code:
the table currently holds customer orders i.e
9 Inch Seafarer Pizza £8.00
9 Inch Beef Eater Pizza £8.00
9 Inch Plus Special Pizza £8.00
15 Inch Vegetarian Pizza £12.00
the seems to echo ok the following to the screen:
9 Inch Seafarer Pizza 8.00,9 Inch Beef Eater Pizza 8.00,9 Inch Plus Special Pizza 8.00,15 Inch Vegetarian Pizza 12.00,
but when viewing the ammendments made to the row, it ONLY inserts the last record: in this case 15 Inch Vegetarian Pizza £12.00
I was wondering if anybody could help me understand what i am doing wrong?
Thanks
I was wondering if somebody could help me as this is driving me crazy.
I am trying to send an array from a mysql_fetch_array result to a seporate table. I have the following code:
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()); }
9 Inch Seafarer Pizza £8.00
9 Inch Beef Eater Pizza £8.00
9 Inch Plus Special Pizza £8.00
15 Inch Vegetarian Pizza £12.00
the
php Syntax (Toggle Plain Text)
echo $value
9 Inch Seafarer Pizza 8.00,9 Inch Beef Eater Pizza 8.00,9 Inch Plus Special Pizza 8.00,15 Inch Vegetarian Pizza 12.00,
but when viewing the ammendments made to the row, it ONLY inserts the last record: in this case 15 Inch Vegetarian Pizza £12.00
I was wondering if anybody could help me understand what i am doing wrong?
Thanks
I think you may want to do something more like:
php Syntax (Toggle Plain Text)
<?php // Assuming there is a open mysql connection $sql = "SELECT item, cost FROM orders_total"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $newValue = $row['item'] .", ". $row['cost']; $sql = "UPDATE orders_complete SET ord_descr='$newValue ' WHERE [...]"; if(!mysql_query($sql)) { user_error("Failed to update row: $newValue", E_USER_NOTICE); } } ?>
Last edited by Atli; Nov 6th, 2008 at 8:19 pm. Reason: Pasted the wrong code.
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
thanks for that,
I will impliment that as soon as I can and let you know how I get on. As Im a new PHP programmer im not too sure what the difference is between the mysql_fetch_array and the mysql_fetch_assoc functions although I have looked it up on the php.net website it doesnt really tell me in dummie language.
thanks again
I will impliment that as soon as I can and let you know how I get on. As Im a new PHP programmer im not too sure what the difference is between the mysql_fetch_array and the mysql_fetch_assoc functions although I have looked it up on the php.net website it doesnt really tell me in dummie language.
thanks again
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
hi again
unfortunitly using the mysql_fetch_assoc didnt resolve the issue. when viewing the row changed by the update query only inserted the last row of the select item,cost from orders_total table
for example:
9 Inch Seafarer Pizza 8.00, 9 Inch Beef Eater Pizza 8.00, 9 Inch Plus Special Pizza 8.00, Hlf lb Garlic Mushroom Cheese burger 3.50, Hlf lb Chicken burger 3.50,
only updates into the orders_complete table the following rather than the total array:
Hlf lb Chicken burger 3.50,
unfortunitly using the mysql_fetch_assoc didnt resolve the issue. when viewing the row changed by the update query only inserted the last row of the select item,cost from orders_total table
for example:
9 Inch Seafarer Pizza 8.00, 9 Inch Beef Eater Pizza 8.00, 9 Inch Plus Special Pizza 8.00, Hlf lb Garlic Mushroom Cheese burger 3.50, Hlf lb Chicken burger 3.50,
only updates into the orders_complete table the following rather than the total array:
Hlf lb Chicken burger 3.50,
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
if i put an inbetween the two }} at the end it seems to insert the firstline of the array into the table orders_complete. I think what its doing is everytime the while loop cycles its writing to the table sucessfully but not remebering the previous keys in the array hence the reason for it only inserting the last array. I think i need a foreach or a for loop to do something else with the code but im not too sure
php Syntax (Toggle Plain Text)
exit();
![]() |
Similar Threads
- Help me with my myspace clone (PHP)
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
- HTML mail subscriiption error (PHP)
Other Threads in the PHP Forum
- Previous Thread: What is solution to this query
- Next Thread: open link in new window - PHP
| Thread Tools | Search this Thread |
.htaccess ajax alerts apache api array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database date display dynamic echo email emptydisplayvalue error errors file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect regex remote script search securephp server sessions shot sms soap source space sql subscription syntax system table tutorial update upload url validation validator variable video web xml youtube





