gpt4 book ai didi

php - 创建数组后用逗号将数组添加到 mysql varchar 行中

转载 作者:行者123 更新时间:2023-11-29 23:53:21 25 4
gpt4 key购买 nike

我有一张大 table ,上面有一些元素。我想根据玩家的游戏水平从该表中检索特定项目。代码提取所有特定项目后,我想将它们添加到数组中(在本例中为“$cart”)。我想将 mysql 行更新为 varchar 字段,该数组由逗号“,”分隔;

我尝试了不同的方法将它们添加到数据库中,但有些不起作用。

这是我的代码:

$sql = mysql_query("select * from iteme where tip != 'Minereu' AND tip != 'Reteta' AND   tip != 'Cooking' AND tip != 'Altele' AND tip != 'Potiuni' AND tip != 'Fragment' AND tip != 'Tools' AND tip != 'Medicina' ");

$numaratoare = 0;
$cart = array();
$nivel_player = mysql_query("select * from membri where id !=0 ");

while($informatie_player = mysql_fetch_array($nivel_player))
{
$nivel_actual_player = lvl($informatie_player['experienta']);
$shop_arme_plus_5 = $nivel_actual_player + 5 ;
if ($nivel_actual_player - 5 == 0 )
$shop_arme_minus_5 = $nivel_actual_player - 5 ;
else
$shop_arme_minus_5 = 0 ;


$shop_arme = mysql_query("select * from iteme where tip = 'Arme' AND level_minim < ".$shop_arme_plus_5." AND level_minim > ".$shop_arme_minus_5." AND vandabil = 1 ");

while($informatie = mysql_fetch_array($shop_arme)) {
$numaratoare ++;
//echo " ".$informatie['nume_ro']." , ";
array_push($cart, $informatie['obiect']);
}
mysql_query("INSERT INTO membri_shop_iteme set iteme_arme = ".$informatie["obiect"]." where id_jucator = ".$informatie_player['id']." "); // Here is the problem.

}

问题出在哪里?我尝试添加 implode(', ', $cart); 但仍然无法将它们添加到数据库中。

感谢您的帮助。

最佳答案

可能是 $informatie["obiect"] 到 $informatie['obiect'] 的字符串问题

  mysql_query("INSERT INTO membri_shop_iteme set iteme_arme = ".$informatie['obiect']." where id_jucator = ".$informatie_player['id']." "); // Here is the problem.

  $newObject=join(",",$cart);
mysql_query("UPDATE membri_shop_iteme SET iteme_arme = '".$newObject."' where id_jucator = ".$informatie_player['id']." "); // Here is the problem.

关于php - 创建数组后用逗号将数组添加到 mysql varchar 行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25487201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com