简体   繁体   English

如何将每列中的 2 个值输入到另一个表中的一列

[英]how to input 2 value from each column to one column in another table

i try to input value of first_name and last_name from table students to column name of table users here is my studentcontroller我尝试从表学生输入名字和姓氏的值到表用户的列名这是我的学生控制器

  public function store(Request $request)
    {
        $user = new User;
        $user->name = $request->first_name&&$request->last_name;
        $user->save();

        $student = new Santri;
        $student->user_id = $user->id;
        $student->first_name = $request->get('first_name');
        $student->last_name = $request->get('last_name');
        $student->save();

 return redirect()->route('student.index');
    }

then the result value='1' in column name at table user然后在表用户的列名中的结果值='1'

how to get value first_name and last_name sorted to column name in table user?如何将值 first_name 和 last_name 排序到表用户中的列名?

Don't use &&, use php's concatenation operator.不要使用 &&,使用 php 的连接运算符。

$user->name = $request->first_name . $request->last_name;

The reason why you're getting 1 as a result is because you're using the && Logical operator.结果得到 1 的原因是因为您使用的是 && 逻辑运算符。 Because php is very weakly typed it assumes anything that isn't a null or a 0 is "True", and by comparing "True" && "True" you get "True" which is 1因为 php 的类型非常弱,它假定任何不是 null 或 0 为“真”,通过比较“真”&&“真”你得到“真”,即 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据另一个表列从一个表中选择一列? - how to select a column from one table according to another table column? Laravel:如何查询表,从每个唯一 item_id 的列中获取第一个值并将其分配给另一个表列 - Laravel: how to query a table, take the first value of from a column for each unique item_id and assign it to another table column HTML 表:从一列(每行)和第二列添加值并将其显示在第三列上 - HTML Table : addition of value from one column(each row) and 2nd column and dispaly it on third column 如何将一个MySql表中的值与PHP中另一个表的列名匹配? - How do I match value from one MySql table to column name of another table in PHP? PHP-将列的值从一个表替换为另一个表 - PHP - Replacing column's value from one table to another MySQL-如何从另一个表控制一个表的“数字”列 - MySQL - How to control `numeric` column of one table from another table MySql中如何将列数据从一张表复制到另一张表? - How to Copy Column data from one table to another table in MySql? 将一个表的值附加到另一个表的列键中 - Append value of one table into column key of another 如何设置表中的一列,而另一表中的列具有特定值? - How can I set one column in a table where a column in another table has a certain value? 如果一个表列为空,如何从另一表获取值 - How to get the value from the other table if one table column is empty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM