如何获得与html中显示的行一样多的输入?

当我单击一个按钮时,我想打开一个带有包含输入的表单的弹出窗口。我没有问题这样做,特殊性是我想要尽可能多的输入(以弹出的形式)作为我的原始窗口中一行的单元格。

基本上我有page1.php那个输出 SQLSELECT查询。对于每一行,我生成一个按钮,在onClick()事件发生时打开一个弹出窗口。我想使用此按钮让用户可以修改一行。

http://img3.mukewang.com/6184d7e30001048306520114.jpg

我这样生成我的表:


        $result = Db::query($requete);


        $texte = "<table class='table table-bordered table-sm'><thead>$table_header</thead>";

        $texte .= "<tbody>";


        if (!pg_num_rows($result)){

            $nb_ligne = "Aucune ligne trouvée !";

        }else{

            $nb_ligne ="Nombre de lignes : ".pg_num_rows($result);

        }

        while($row = pg_fetch_row($result)){

            $texte .= "<tr><td><button class=\"btn btn-primary\" type=\"button\" id=\"buttonCreate\" onclick=\"OuvrirPopup('update.php','', 'resizable=no, location=no, width=800, height=1000, menubar=no,status=no, scrollbars=no')\"></button></td>";

            foreach ($row as $value){

                $texte .= "<td style='word-break: keep-all'>$value</td>";

            }

            $texte .= "</tr>";

        }

        $texte .= "</tbody></table>";


        $response = new Response();

        $response->assign('nb_ligne', 'innerHTML', $nb_ligne);

        $response->assign('tableau_resultat', 'innerHTML', $texte);


        return $response;

我不知道如何inputs连续生成与单元格一样多的单元格


并且


如何inputs使用已经填充的内容设置默认值。


我想从中学习,所以,如果可能的话,向我解释我在这里做错了什么,或者我的方法是否缺乏洞察力。


白猪掌柜的
浏览 150回答 1
1回答

繁华开满天机

在文件中,page1.php您将执行以下操作:&nbsp; &nbsp; $result = Db::query($query); // the query should return column ID for each row&nbsp; &nbsp; $text = "<table class='table table-bordered table-sm'><thead>$table_header</thead><tbody>";&nbsp; &nbsp; if (!pg_num_rows($result))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $no_results = "Nothing was found !";&nbsp; &nbsp; }&nbsp; &nbsp; else&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $no_results = "Results found: ".pg_num_rows($result);&nbsp; &nbsp; }&nbsp; &nbsp; while($row = pg_fetch_row($result))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; // the popup will open `page2.php?id=ID-of-the-row`&nbsp; &nbsp; &nbsp; $text .= "<tr><td><button class='btn btn-primary' type='button' id='buttonCreate' onclick='showPopup(\"update.php?id=".$row['id']."\")'>EDIT</button></td>";&nbsp; &nbsp; &nbsp; foreach ($row as $value)&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $text .= "<td style='word-break: keep-all;'>".htmlspecialchars($value)."</td>";&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; $text .= "</tr>";&nbsp; &nbsp; }&nbsp; &nbsp; $text .= "</tbody></table>";&nbsp; &nbsp; $response = new Response();&nbsp; &nbsp; $response->assign('no_results', 'innerHTML', $no_results);&nbsp; &nbsp; $response->assign('table_body', 'innerHTML', $text);&nbsp; &nbsp; return $response;然后,在文件中,page2.php您将执行以下操作:&nbsp; &nbsp; $result = Db::query($query); // the query will use $_GET['id'] in order to fetch the specific row&nbsp; &nbsp; $text = "<table class='table table-bordered table-sm'><thead>$table_header</thead><tbody>";&nbsp; &nbsp; if (!pg_num_rows($result))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $no_results = "Nothing was found !";&nbsp; &nbsp; }&nbsp; &nbsp; else&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $no_results = "Results found: ".pg_num_rows($result);&nbsp; &nbsp; }&nbsp; &nbsp; // there should be no more than 1 row&nbsp; &nbsp; while($row = pg_fetch_assoc($result))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $text .= "<tr>";&nbsp; &nbsp; &nbsp; foreach ($row as $key => $value)&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $text .= "<td style='word-break: keep-all;'><input type=text name='".$key."' value='".htmlspecialchars($value)."'></td>";&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; $text .= "</tr>";&nbsp; &nbsp; }&nbsp; &nbsp; $text .= "</tbody></table>";&nbsp; &nbsp; $response = new Response();&nbsp; &nbsp; $response->assign('no_results', 'innerHTML', $no_results);&nbsp; &nbsp; $response->assign('table_body', 'innerHTML', $text);&nbsp; &nbsp; return $response;
打开App,查看更多内容
随时随地看视频慕课网APP