帮助将php数组发送到mysql表 [英] help in sending php array to mysql table
问题描述
我想知道是否有人可以帮助我。这让我发疯了。
我试图从表total_orders的mysql_fetch_assoc结果发送一个数组到表orders_complete。我有以下代码:
[php]
<?php include(" config.php"); $ 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 date =''xx / xx / xx''and time =''xx:xx:xx''" ;; if(!mysql_query($ sql)){user_error(" Failed to update row:$ newValue",E_USER_NOTICE); }>
[/ php]
以上代码使用time = xx成功更新行:xx:Xx和date = xx / xx / xx但是...
当我在orders_complete表中搜索新更新的行时。它似乎只是进入表中数组的最后一个键而不是FULL数组
即
total_orders表echos
12披萨£12
半磅汉堡£3.40
筹码的一部分
将进入数据库只有芯片的侧面部分
如果我放一个退出();在脚本末尾显示的2 end}}之间
当我为该行执行搜索时它只显示为输入
12"比萨饼12英镑
,别无其他。
我想知道是否有人可以帮助我做错。它看起来像循环时的while循环覆盖每个条目因此我只能看到数组的1个值而不是用a,
sql分隔的总数组=" SELECT item,cost FROM orders_total" ;;
result = mysql_query(
sql)或die(mysql_error());而(
I was wondering if somebody could help me. this is driving me crazy.
I am trying to send an array from a mysql_fetch_assoc result from table total_orders to table orders_complete. I have the following code:
[php]
<?php include("config.php");$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 date=''xx/xx/xx'' and time=''xx:xx:xx''"; if(!mysql_query($sql)) { user_error("Failed to update row: $newValue", E_USER_NOTICE); }}?>
[/php]
The above code sucessfully updates the row with time=xx:xx:Xx and date=xx/xx/xx but...
When i search the orders_complete table for the new updated row. It only seems to enter into the table the last key of the array and not the FULL array
i.e.
total_orders table echos
12" pizza £12
half lb burger £3.40
side portion of chips
would enter into the database ONLY side portion of chips
if i put a exit(); inbetween the 2 end }} shown at the end of the script
when I do a seach for the row it only shows as entered
12" pizza £12
and nothing else.
I was wondering if somebody could help me in what im doing wrong. it looks like that the while loop when cycled is overwriting each entry hence I can only see 1 value of the array rather than the total array seporated with a ,
sql = "SELECT item, cost FROM orders_total";
result = mysql_query(
sql) or die(mysql_error()); while(
这篇关于帮助将php数组发送到mysql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!