将数据插入SQL表,但从具有不同列名的另一个表中获取特定列数据

时间:2017-08-20 11:57:35

标签: php mysql sql-server

我正在寻求帮助,

我有两个表,一个是用户,另一个是 land 。用户可以拥有多块土地。

我的用户表持有 - ID | USERNAME |通过 Land表保存 - ID | Land_ID | Land_Name

我正在尝试创建一个SQL语句,这将允许我创建一个新的' land'记录,但它将填充' Land_ID'使用' ID'来自users表。因此:

ID为1的用户的土地名称为绿色,Land_ID 1表示他们拥有该土地?

我希望这是有道理的。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

<?php
defined( '_JEXEC' ) or die();

class plgContentShortcode extends JPlugin
{  
    protected $autoloadLanguage = true;
    function onContentPrepare ($context, $article, $params, $limitstart)
    {
    // preg_match("/([[]countdowntimer(.*)[]])/", $article->text, $tmp, PREG_OFFSET_CAPTURE);
    // I'm trying to extract parameters in this way

    // preg_match("/date=\"([0-9-]+)\"/", $tmp[2][0], $return_tmp['date'], PREG_OFFSET_CAPTURE); //date
    // preg_match("/time=\"([0-9:]+)\"/", $tmp[2][0], $return_tmp['time'], PREG_OFFSET_CAPTURE); // time

    $article->text = preg_replace('/([[]countdowntimer(.*)[]])/', '{loadmodule mod_countdowntimer}', $article->text);
    return true;
    }
}
?>

额外信息:

如果这是来自HTML表单,您可以输入用户会话ID作为隐藏输入:

$var = $session_id; //use whatever variable you use when collecting the session id, from what I gather you are using the unique id from the users table for this.

$sql = "INSERT INTO land (land_id, land_name) VALUES ('$var', '$land_name')"

在这种情况下,您可以将变量定义为:

<input type = "hidden" name="id" value="<?php echo['id']; ?>">
相关问题