• <bdo id='0NUQx'></bdo><ul id='0NUQx'></ul>
      <i id='0NUQx'><tr id='0NUQx'><dt id='0NUQx'><q id='0NUQx'><span id='0NUQx'><b id='0NUQx'><form id='0NUQx'><ins id='0NUQx'></ins><ul id='0NUQx'></ul><sub id='0NUQx'></sub></form><legend id='0NUQx'></legend><bdo id='0NUQx'><pre id='0NUQx'><center id='0NUQx'></center></pre></bdo></b><th id='0NUQx'></th></span></q></dt></tr></i><div id='0NUQx'><tfoot id='0NUQx'></tfoot><dl id='0NUQx'><fieldset id='0NUQx'></fieldset></dl></div>
      <legend id='0NUQx'><style id='0NUQx'><dir id='0NUQx'><q id='0NUQx'></q></dir></style></legend>
      <tfoot id='0NUQx'></tfoot>
    1. <small id='0NUQx'></small><noframes id='0NUQx'>

    2. 如何在数据库的同一列中保存多个行的输入?

      时间:2023-09-22
      <i id='fcueC'><tr id='fcueC'><dt id='fcueC'><q id='fcueC'><span id='fcueC'><b id='fcueC'><form id='fcueC'><ins id='fcueC'></ins><ul id='fcueC'></ul><sub id='fcueC'></sub></form><legend id='fcueC'></legend><bdo id='fcueC'><pre id='fcueC'><center id='fcueC'></center></pre></bdo></b><th id='fcueC'></th></span></q></dt></tr></i><div id='fcueC'><tfoot id='fcueC'></tfoot><dl id='fcueC'><fieldset id='fcueC'></fieldset></dl></div>

      <small id='fcueC'></small><noframes id='fcueC'>

        <tbody id='fcueC'></tbody>
      • <tfoot id='fcueC'></tfoot>

              <bdo id='fcueC'></bdo><ul id='fcueC'></ul>
              <legend id='fcueC'><style id='fcueC'><dir id='fcueC'><q id='fcueC'></q></dir></style></legend>

                本文介绍了如何在数据库的同一列中保存多个行的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                数据库表

                id  | title | reading | writing | speaking
                

                form.blade.php

                form.blade.php

                <table><tr>
                    <th>Language</th>
                    <th>Reading</th>
                    <th>Writing</th>
                    <th>Speaking</th>
                </tr>
                <tr>
                    <td>
                        <input name="TitleText_1" id="TitleText_1"/></td>
                    <td>
                        <select name="ReadingText_1" id="ReadingText_1">
                        <option value="High">High</option>
                        <option value="Medium">Medium</option>
                        <option value="Low">Low</option>
                        </select>
                    </td>
                    <td>
                        <select name="langWrittingText_1" id="WrittingText_1">
                        <option value="High">High</option>
                        <option value="Medium">Medium</option>
                        <option value="Low">Low</option>
                        </select>
                    </td>
                    <td>
                        <select name="SpeakingText_1" id="SpeakingText_1">
                        <option value="High">High</option>
                        <option value="Medium">Medium</option>
                        <option value="Low">Low</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                       <input name="TitleText_2" id="TitleText_2" /></td>
                    <td>
                        <select name="ReadingText_2" id="ReadingText_2">
                        <option value="High">High</option>
                        <option value="Medium">Medium</option>
                        <option value="Low">Low</option>
                        </select>
                    </td>
                    <td>
                        <select name="WrittingText_2" id="WrittingText_2">
                        <option value="High">High</option>
                        <option value="Medium">Medium</option>
                        <option value="Low">Low</option>
                    </select>
                    </td>
                    <td>
                        <select name="SpeakingText_2" id="SpeakingText_2">
                        <option value="High">High</option>
                        <option value="Medium">Medium</option>
                        <option value="Low">Low</option>
                        </select>
                    </td>
                

                语言控制器.php

                   $languages = Language::create(array
                
                   (
                
                   'title' => $input['TitleText_1'],
                
                   'reading' => $input['ReadingText_1'],
                
                   'writting' => $input['WrittingText_1'],
                
                   'speaking' => $input['SpeakingText_1'],
                $languages->save();
                
                  ));
                

                我想要将控制器代码保存到数据库中.因为有多个相同标签的输入.

                I want what will be the controller code to save into the database. as there are multiple inputs of same label.

                如何获取控制器中的所有输入?另外如何将多个输入保存到同一列的数据库中?我是 Laravel 4.2 的新手.

                How to get all the inputs in controller? Also how to save multiple inputs into database of same column? I am a newbie of Laravel 4.2.

                推荐答案

                像这样使用多个同名输入

                Use multiple inputs with same name like this

                <input name="TitleText[]" />
                <select name="ReadingText[]" >
                ...
                <select name="langWrittingText[]">
                ...
                <select name="SpeakingText[]">
                ...
                

                这样数据就会以数组的形式发布.假设所有的输入/选择都需要用户填写

                This way the data will be posted in the form of an array. Assuming that all the inputs/select are required to be filled by the user

                在你的控制器中你可以做这样的事情

                In your controller you can do something like this

                $count = count($input['TitleText']); // here we will know how many entries have been posted
                $languages = array();
                for($i=0; $i<$count; $i++){
                   if(!empty($input['TitleText'][$i])){
                     array_push($languages, array( // iterate through each entry and create an array of inputs
                      'title' => $input['TitleText'][$i], 
                      'reading' => $input['ReadingText'][$i], 
                      'writting' => $input['WrittingText'][$i],
                      'speaking' => $input['SpeakingText'][$i]
                     ));
                   }
                }
                Languages::insert($languages); // save the array of models at once
                

                希望这会有所帮助.

                这篇关于如何在数据库的同一列中保存多个行的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Laravel Eloquent/Query Builder 中 LEFT JOIN 的 ON 子句中的 下一篇:循环遍历集合-Laravel

                相关文章

                最新文章

                <small id='6WrP9'></small><noframes id='6WrP9'>

                  <bdo id='6WrP9'></bdo><ul id='6WrP9'></ul>
              1. <tfoot id='6WrP9'></tfoot>
              2. <legend id='6WrP9'><style id='6WrP9'><dir id='6WrP9'><q id='6WrP9'></q></dir></style></legend>

                1. <i id='6WrP9'><tr id='6WrP9'><dt id='6WrP9'><q id='6WrP9'><span id='6WrP9'><b id='6WrP9'><form id='6WrP9'><ins id='6WrP9'></ins><ul id='6WrP9'></ul><sub id='6WrP9'></sub></form><legend id='6WrP9'></legend><bdo id='6WrP9'><pre id='6WrP9'><center id='6WrP9'></center></pre></bdo></b><th id='6WrP9'></th></span></q></dt></tr></i><div id='6WrP9'><tfoot id='6WrP9'></tfoot><dl id='6WrP9'><fieldset id='6WrP9'></fieldset></dl></div>