Php Laravel更新多行
我是Laravel的初学者,我的代码很难处理。 我想将我的站点选项和详细信息存储在数据库中,而我遇到的问题是我不知道如何更新多行,也许我的数据库结构也不是最好的 数据库Php Laravel更新多行,php,sql-update,laravel,Php,Sql Update,Laravel,我是Laravel的初学者,我的代码很难处理。 我想将我的站点选项和详细信息存储在数据库中,而我遇到的问题是我不知道如何更新多行,也许我的数据库结构也不是最好的 数据库 id | option_name | option_value 1 | site_name | Website name 2 | site_slogen | Website slogen 3 | site_description | Website description 4 | pos
id | option_name | option_value
1 | site_name | Website name
2 | site_slogen | Website slogen
3 | site_description | Website description
4 | post_per_pages | 20
我的表格
{{ Form::open('admin/options', 'POST', array('class' => 'span5 no-float centered')) }}
@foreach($options as $option)
<?php $name = str_replace('_', ' ', ucfirst($option->option_name)); ?>
{{ Form::label($name, $name) }}
@if($option->option_name == "site_description")
{{ Form::textarea($option->option_name, $option->option_value, array('class' => 'input-block-level', 'rows' => '5')) }}
@else
{{ Form::text($option->option_name, $option->option_value, array('class' => 'input-block-level')) }}
@endif
{{ $errors->has($option->option_name) ? '<p class="val_error">' .$errors->first($option->option_name). '</p>' : '' }}
{{ Form::hidden('id[]', $option->id) }}
@endforeach
{{ Form::button('Update options', array('class' => 'btn btn-primary btn-block')) }}
我知道这不是最好的,但我正在努力。
有人能给我一个关于多重更新的提示吗
我试过了,但我迷路了您可以循环浏览行并保存它们
$inputs = Input::all();
$content = Content::find($id);
foreach($inputs as $key => $value)
{
$content->$key = $value;
}
$content->save();
您可以循环行并保存它们
$inputs = Input::all();
$content = Content::find($id);
foreach($inputs as $key => $value)
{
$content->$key = $value;
}
$content->save();
您可以构建一个查询,如下所示:
YourTable::query()->where('YourTableColumn', 'Variable/Field to match against')->update(array('Fiel' => $new_username));
在“更新”中,您可以传递一个字段数组及其值,您要为所有获取的行更新该数组。您可以构建一个查询,如下所示:
YourTable::query()->where('YourTableColumn', 'Variable/Field to match against')->update(array('Fiel' => $new_username));
在“更新”中,您可以传递字段数组及其值,您要为所有获取的行更新这些值。哦,我想知道它会影响查询的数量
$inputs = Input::all();
foreach($inputs as $key => $value)
{
$content = Content::find($id);
$content->$key = $value;
$content->save();
}
哦,我想知道它会影响查询的数量
$inputs = Input::all();
foreach($inputs as $key => $value)
{
$content = Content::find($id);
$content->$key = $value;
$content->save();
}
重复目标表,将其命名为“mytable_insertbypass”,操作前为trunca,然后插入优化,插入后,进行查询以更新: 更新产品,产品\u插入旁路 设置products.price=products\u insertbypass.price 其中products.id=products\u insertbypass
法瓦罗罗规则 复制目标表,在操作前将其命名为“mytable_insertbypass”,然后插入优化,插入后,进行查询以更新: 更新产品,产品\u插入旁路 设置products.price=products\u insertbypass.price 其中products.id=products\u insertbypass
法瓦罗罗规则 更新多行。。。。好啊但需要更新的标准是什么?然后问题以多重插入结束。。。。伟大的更新多行。。。。好啊但需要更新的标准是什么?然后问题以多重插入结束。。。。伟大的这是错误的,您正在更新多列,而不是多行。这是在一行中更新列。这是错误的,您正在更新多列,而不是多行。这是在一行中更新列