Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
模态仅显示一个人-php mysql_Php_Mysql_Modal Dialog - Fatal编程技术网

模态仅显示一个人-php mysql

模态仅显示一个人-php mysql,php,mysql,modal-dialog,Php,Mysql,Modal Dialog,当点击图片时,我会弹出一个对话框。对话框代码在这里以粗体显示。在我的HTML代码中,我每次都必须为每个人将“openModal”更改为openModal2、openModal3等。你对这里的工作有什么想法吗 $sql = "SELECT * FROM person2"; if ($result = mysqli_query($connection, $sql)) { // loop through the data //create 4 columns for the

当点击图片时,我会弹出一个对话框。对话框代码在这里以粗体显示。在我的HTML代码中,我每次都必须为每个人将“openModal”更改为openModal2、openModal3等。你对这里的工作有什么想法吗

$sql = "SELECT * FROM person2";

if ($result = mysqli_query($connection, $sql)) {    
    // loop through the data
    //create 4 columns for the table
    $columns=4;
    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
        // the % operator gives the remainder of a division of two values
        // in this case, 0/4, this tells the table row to jump to a new row
        // if there are already 4 columns in one row
        if($i % $columns == 0){

                   //begin table row
                   echo "<tr>";
        }

         echo '<td class="staffImage badgeText frameImage displayInLine">
                <a href=#openModal><img src="images/staff/'.$row["imgName"].'.jpg"></a><br> 
                <strong>'.$row["firstName"].'</strong>
                <strong>'.$row["lastName"].'</strong><br>
                **<div id="openModal" class="modalDialog">
                    <div>
                               <a href="#close" title="Close" class="close">X</a>
                               <h2>' . $row["firstName"] .
                               $row["lastName"].'</h2><br>
                               <img class="floatLeft" src="images/staff/'.$row["imgName"] .'.jpg">
                               <p><strong>Hire Date:</strong>'.$row["hireDate"].'<br>
                               <p><strong>Major:</strong>'.$row["major"];

                                          //if the field "major2" (Double Major) is not null, display it
                             if($row["major2"] != NULL)
                             {
                               echo ' & '.$row["major2"].'<br>';
                             }

                             //if the field "minor" is not null, display it
                             if($row["minor"] != NULL)
                             {
                               echo '<br> Minor: '.$row["minor"].'<br>';
                             }

                                           //if the field "concentration" is not null, display it 
                             if($row["concentration"] != NULL)
                             {
                               echo '<br> Concentration: '.$row["concentration"].'<br>';
                             }

                    '</div>
                </div>
                <br><strong>'.$row["firstName"].'</strong>
                </div> ';**
            //end <td>       
        echo '</td>';
$sql=“从person2选择*;
如果($result=mysqli_query($connection,$sql)){
//循环浏览数据
//为表创建4列
$columns=4;
$i=0;
while($row=mysqli\u fetch\u assoc($result)){
//%运算符给出两个值除后的余数
//在本例中为0/4,这告诉表行跳转到新行
//如果一行中已有4列
如果($i%$columns==0){
//开始表行
回声“;
}
回声'

。$row[“firstName”]。 。$row[“lastName”]。
** “.$row[“firstName”]。 $row[“lastName”]。
聘用日期:。$row[“hireDate”]。
主修:。$row[“主修”]; //如果字段“major2”(双主)不为空,则显示该字段 如果($row[“major2”]!=NULL) { 回显“&.”行[“主2”]。
; } //如果字段“次要”不为空,则显示它 如果($row[“minor”]!=NULL) { 回显“
次要:”.$row[“次要”]。
; } //如果“浓度”字段不为空,则显示该字段 如果($row[“浓度”!=NULL) { 回显'
浓度:'.$row[“浓度”].
'; } '
。$row[“firstName”]。 ';** //结束 回声';
使用当前方法,当循环和模式id
openModal
重复时,内部有模式,在整个文档中id必须是唯一的,要打开正确的模式,只需将行
id
分配给模式触发器和模式本身

$sql = "SELECT * FROM person2";

if ($result = mysqli_query($connection, $sql)) {    
    // loop through the data
    //create 4 columns for the table
    $columns=4;
    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
        // the % operator gives the remainder of a division of two values
        // in this case, 0/4, this tells the table row to jump to a new row
        // if there are already 4 columns in one row
        if($i % $columns == 0){

                   //begin table row
                   echo "<tr>";
        }

         echo '<td class="staffImage badgeText frameImage displayInLine">
                <a href=#openModal><img src="images/staff/'.$row["imgName"].'.jpg"></a><br> 
                <strong>'.$row["firstName"].'</strong>
                <strong>'.$row["lastName"].'</strong><br>
                **<div id="openModal" class="modalDialog">
                    <div>
                               <a href="#close" title="Close" class="close">X</a>
                               <h2>' . $row["firstName"] .
                               $row["lastName"].'</h2><br>
                               <img class="floatLeft" src="images/staff/'.$row["imgName"] .'.jpg">
                               <p><strong>Hire Date:</strong>'.$row["hireDate"].'<br>
                               <p><strong>Major:</strong>'.$row["major"];

                                          //if the field "major2" (Double Major) is not null, display it
                             if($row["major2"] != NULL)
                             {
                               echo ' & '.$row["major2"].'<br>';
                             }

                             //if the field "minor" is not null, display it
                             if($row["minor"] != NULL)
                             {
                               echo '<br> Minor: '.$row["minor"].'<br>';
                             }

                                           //if the field "concentration" is not null, display it 
                             if($row["concentration"] != NULL)
                             {
                               echo '<br> Concentration: '.$row["concentration"].'<br>';
                             }

                    '</div>
                </div>
                <br><strong>'.$row["firstName"].'</strong>
                </div> ';**
            //end <td>       
        echo '</td>';
模态触发链

$sql = "SELECT * FROM person2";

if ($result = mysqli_query($connection, $sql)) {    
    // loop through the data
    //create 4 columns for the table
    $columns=4;
    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
        // the % operator gives the remainder of a division of two values
        // in this case, 0/4, this tells the table row to jump to a new row
        // if there are already 4 columns in one row
        if($i % $columns == 0){

                   //begin table row
                   echo "<tr>";
        }

         echo '<td class="staffImage badgeText frameImage displayInLine">
                <a href=#openModal><img src="images/staff/'.$row["imgName"].'.jpg"></a><br> 
                <strong>'.$row["firstName"].'</strong>
                <strong>'.$row["lastName"].'</strong><br>
                **<div id="openModal" class="modalDialog">
                    <div>
                               <a href="#close" title="Close" class="close">X</a>
                               <h2>' . $row["firstName"] .
                               $row["lastName"].'</h2><br>
                               <img class="floatLeft" src="images/staff/'.$row["imgName"] .'.jpg">
                               <p><strong>Hire Date:</strong>'.$row["hireDate"].'<br>
                               <p><strong>Major:</strong>'.$row["major"];

                                          //if the field "major2" (Double Major) is not null, display it
                             if($row["major2"] != NULL)
                             {
                               echo ' & '.$row["major2"].'<br>';
                             }

                             //if the field "minor" is not null, display it
                             if($row["minor"] != NULL)
                             {
                               echo '<br> Minor: '.$row["minor"].'<br>';
                             }

                                           //if the field "concentration" is not null, display it 
                             if($row["concentration"] != NULL)
                             {
                               echo '<br> Concentration: '.$row["concentration"].'<br>';
                             }

                    '</div>
                </div>
                <br><strong>'.$row["firstName"].'</strong>
                </div> ';**
            //end <td>       
        echo '</td>';
<a href="#openModal'.$row["rowid"].'"><img src="images/staff/'.$row["imgName"].'.jpg"></a>

和模态

$sql = "SELECT * FROM person2";

if ($result = mysqli_query($connection, $sql)) {    
    // loop through the data
    //create 4 columns for the table
    $columns=4;
    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
        // the % operator gives the remainder of a division of two values
        // in this case, 0/4, this tells the table row to jump to a new row
        // if there are already 4 columns in one row
        if($i % $columns == 0){

                   //begin table row
                   echo "<tr>";
        }

         echo '<td class="staffImage badgeText frameImage displayInLine">
                <a href=#openModal><img src="images/staff/'.$row["imgName"].'.jpg"></a><br> 
                <strong>'.$row["firstName"].'</strong>
                <strong>'.$row["lastName"].'</strong><br>
                **<div id="openModal" class="modalDialog">
                    <div>
                               <a href="#close" title="Close" class="close">X</a>
                               <h2>' . $row["firstName"] .
                               $row["lastName"].'</h2><br>
                               <img class="floatLeft" src="images/staff/'.$row["imgName"] .'.jpg">
                               <p><strong>Hire Date:</strong>'.$row["hireDate"].'<br>
                               <p><strong>Major:</strong>'.$row["major"];

                                          //if the field "major2" (Double Major) is not null, display it
                             if($row["major2"] != NULL)
                             {
                               echo ' & '.$row["major2"].'<br>';
                             }

                             //if the field "minor" is not null, display it
                             if($row["minor"] != NULL)
                             {
                               echo '<br> Minor: '.$row["minor"].'<br>';
                             }

                                           //if the field "concentration" is not null, display it 
                             if($row["concentration"] != NULL)
                             {
                               echo '<br> Concentration: '.$row["concentration"].'<br>';
                             }

                    '</div>
                </div>
                <br><strong>'.$row["firstName"].'</strong>
                </div> ';**
            //end <td>       
        echo '</td>';
<div id="openModal'.$row["rowid"].'" class="modalDialog"></div>

脚注:根据表更改
$row[“rowid”]
的值以更正列名称

$sql = "SELECT * FROM person2";

if ($result = mysqli_query($connection, $sql)) {    
    // loop through the data
    //create 4 columns for the table
    $columns=4;
    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
        // the % operator gives the remainder of a division of two values
        // in this case, 0/4, this tells the table row to jump to a new row
        // if there are already 4 columns in one row
        if($i % $columns == 0){

                   //begin table row
                   echo "<tr>";
        }

         echo '<td class="staffImage badgeText frameImage displayInLine">
                <a href=#openModal><img src="images/staff/'.$row["imgName"].'.jpg"></a><br> 
                <strong>'.$row["firstName"].'</strong>
                <strong>'.$row["lastName"].'</strong><br>
                **<div id="openModal" class="modalDialog">
                    <div>
                               <a href="#close" title="Close" class="close">X</a>
                               <h2>' . $row["firstName"] .
                               $row["lastName"].'</h2><br>
                               <img class="floatLeft" src="images/staff/'.$row["imgName"] .'.jpg">
                               <p><strong>Hire Date:</strong>'.$row["hireDate"].'<br>
                               <p><strong>Major:</strong>'.$row["major"];

                                          //if the field "major2" (Double Major) is not null, display it
                             if($row["major2"] != NULL)
                             {
                               echo ' & '.$row["major2"].'<br>';
                             }

                             //if the field "minor" is not null, display it
                             if($row["minor"] != NULL)
                             {
                               echo '<br> Minor: '.$row["minor"].'<br>';
                             }

                                           //if the field "concentration" is not null, display it 
                             if($row["concentration"] != NULL)
                             {
                               echo '<br> Concentration: '.$row["concentration"].'<br>';
                             }

                    '</div>
                </div>
                <br><strong>'.$row["firstName"].'</strong>
                </div> ';**
            //end <td>       
        echo '</td>';

另一种方法是通过Ajax方法,你可以在谷歌上或搜索上找到很多例子。

这是因为你正在循环中创建一个modalDialog。只需创建一个modalDialog并将值传递给它,而不是创建多个不必要的modal。在单独的页面中创建模式对话框??对不起,我不熟悉这个,请不要“我什么都不知道:/效果很好!我知道我需要一个人在那里的某个地方,但不知道在哪里!非常感谢!
$sql = "SELECT * FROM person2";

if ($result = mysqli_query($connection, $sql)) {    
    // loop through the data
    //create 4 columns for the table
    $columns=4;
    $i = 0;
    while($row = mysqli_fetch_assoc($result)){
        // the % operator gives the remainder of a division of two values
        // in this case, 0/4, this tells the table row to jump to a new row
        // if there are already 4 columns in one row
        if($i % $columns == 0){

                   //begin table row
                   echo "<tr>";
        }

         echo '<td class="staffImage badgeText frameImage displayInLine">
                <a href=#openModal><img src="images/staff/'.$row["imgName"].'.jpg"></a><br> 
                <strong>'.$row["firstName"].'</strong>
                <strong>'.$row["lastName"].'</strong><br>
                **<div id="openModal" class="modalDialog">
                    <div>
                               <a href="#close" title="Close" class="close">X</a>
                               <h2>' . $row["firstName"] .
                               $row["lastName"].'</h2><br>
                               <img class="floatLeft" src="images/staff/'.$row["imgName"] .'.jpg">
                               <p><strong>Hire Date:</strong>'.$row["hireDate"].'<br>
                               <p><strong>Major:</strong>'.$row["major"];

                                          //if the field "major2" (Double Major) is not null, display it
                             if($row["major2"] != NULL)
                             {
                               echo ' & '.$row["major2"].'<br>';
                             }

                             //if the field "minor" is not null, display it
                             if($row["minor"] != NULL)
                             {
                               echo '<br> Minor: '.$row["minor"].'<br>';
                             }

                                           //if the field "concentration" is not null, display it 
                             if($row["concentration"] != NULL)
                             {
                               echo '<br> Concentration: '.$row["concentration"].'<br>';
                             }

                    '</div>
                </div>
                <br><strong>'.$row["firstName"].'</strong>
                </div> ';**
            //end <td>       
        echo '</td>';