【问题标题】:insert entries in multiple tables in php在php中的多个表中插入条目
【发布时间】:2011-01-11 04:34:18
【问题描述】:

我在 tizag.com 上找到了本教程。但它是用于显示来自不同表的条目。 如何进行插入?

         <?php
    // Make a MySQL Connection
   // Construct our join query
      $query = "SELECT family.Position, food.Meal ".
      "FROM family, food ".
"WHERE family.Position = food.Position";

      $result = mysql_query($query) or die(mysql_error());


      // Print out the contents of each row into a table 
     while($row = mysql_fetch_array($result)){
echo $row['Position']. " - ". $row['Meal'];
echo "<br />";
      }
      ?>

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    您的意思是通过一个查询将数据插入到多个数据库表中?
    不能。

    阅读MySQL INSERT syntax reference

    当然,您可以循环访问您的数据,例如将其逐步插入到各种表格中,但如果没有您身边的真实代码,则很难提供帮助。

    【讨论】:

    • 谢谢,我从没想过通常的插入语句会这样做。它只是添加了 2 个用于插入 2 个表的 sql 查询。
    【解决方案2】:

    同站有教程:SQL Tutorial - Insert

    这也很有用:PHP MySQL Insert Into

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多