douyi6818 2013-01-02 12:26
浏览 28
已采纳

将一个行列表从一个表传输到另一个表

I have searched everywhere but couldn't find a viable solution to this. Maybe i'm not going about this the right way. I have a list of comma separeated values in an array of ID's which refrences image_id's in a 'temp_image' table. Now i need to slect all the info about the all the images with image_id's in that array and tranfer them form the 'temp_image' table to the 'images' table.

$IMgids = array(1,2,3,4,5,9); etc how does my query look like? What should my where clause look like. I'm comfortable with transfering one row but in this case it could be as much as 50 rows. Any ideas how i could go about this?

  • 写回答

1条回答 默认 最新

  • douzou0073 2013-01-02 12:32
    关注

    From the little information you posted I'd say you need these two details:

    1. the IN operator for the WHERE clause, so that you can reference all entries that are referenced by your array at once: SELECT ... FROM ... WHERE id IN (1,2,3,4,5,9);. You probably want to construct the id set inside the clause by using phps implode() function: implode(',',$IMgids)

    2. the sub query principle for inserting multiple rows into a table that are read from another table. Consult the mysql (online) documentation for this. Something like this: INSERT INTO images (SELECT * FROM temp_images WHERE...);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用