dongshan0202405 2011-04-09 06:30
浏览 33
已采纳

PHP foreach插入语句与数组的问题

Hey guys, i'm currently learning php and I need to do this

  $connection = mysql_open();
  $likes= array();
  foreach($likes as $like)
  {

  $insert3 = "insert into ProfileInterests " .
    "values ('$id', '$like', null)";
  $result3 = @ mysql_query ($insert3, $connection)
    or showerror();

  }
  mysql_close($connection)
    or showerror();

For some reason this does not work =/ I don't know why. $likes is an array which was a user input. I need it to insert into the table it multiple times until all of the things in the array are in.

EDIT I fixed the issue where I was closing it in my foreach loop. mysql_open is my own function btw.

Any ideas?

  • 写回答

5条回答 默认 最新

  • doufeng2877 2011-04-09 06:37
    关注

    For one $likes is an empty array in your example, I am assuming you fix that in the code you run.

    The second is you close the MySQL connection the first the time the loop would run, which would prevent subsequent MySQL queries from running.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题