dsf23223 2014-11-26 18:04
浏览 13

插入2个不同的表格

I'm trying to INSERT certain items ORDER BY monster names,

For example there is an monster called 'SPIDER' this monster has certain items for example: 'bones, legs, more items' the drops of SPIDER are all in 'log_mitem'.

So my problem is when I hit SUBMIT I want just to create a 'log_create' which creates with success, but in the table 'log_drops' I need to INSERT all items of monster spider for E.X. as you see I've used $items and $dropslq for this one but it doesn't work.

$name = $db->real_escape_string(trim($_POST['name']));
$id = $db->real_escape_string(trim($_POST['id']));
$name2 = preg_replace('/\s+/', '', $name);
$game = $db->real_escape_string(trim($_POST['game']));
$info = $db->real_escape_string(trim($_POST['info'])); 
$mobname = $db->real_escape_string(trim($_POST['mobname']));
$sql = "INSERT INTO log_create(`name`, name2, game, monster, info)VALUES('$name', '$name2', '$game', '$mobname', '$info')";
$drop = "SELECT itemname FROM log_mitem ON mobname = '".$mobname."'";
if($dropres = $db->query($drop))
    $items = $dropres->itemname;
$dropslq = "INSERT INTO log_drops(item, mobname, game, log_id, log_name)VALUES('$items', '$mobname', '$game', '$id', '$name')";
  • 写回答

2条回答 默认 最新

  • douchao1879 2014-11-26 18:12
    关注

    If you're trying to insert multiple items, you need to do so in a multi-insert clause or a loop. Otherwise, you could serialize your items array into delimited values (assuming that the item name doesn't include that delimiter), and use implode()/explode() in php to serialize or deseralize. You also could look into using PHP's serialize()/deseralize() functions as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程