在链接中传递数据库PHP变量,以在引导程序MODAL中打开数据库中的特定详细信息

时间:2016-03-09 16:50:17

标签: php database variables modal-dialog

/* When this link is clicked, the bootstrap modal should open with the particular detail from database.*/


<?php

    $con = mysqli_connect("localhost", "root", "","tpevent");

    if(!isset($con))
    {
        die("Database Not Found");
    }
                   $schkt1= mysqli_query($con, "select * from t_tevent");

                    echo" <table>
                            <thead>
                              <tr>

                                <th>Title</th>
                                <th>Date</th>
                                <th>Venue</th>
                                <th>Uploaded On</th>
                              </tr>
                            </thead>
                        <tbody>";

                  while($stevt = mysqli_fetch_array($schkt1))
                        {


                           echo "<tr>";

                            echo "<td> <a style='cursor:pointer; text-decoration: none;' 
                                data-toggle='modal' data-target='#thisdiv'> <strong>" . $stevt[1] ."</strong></a></td>";


                           echo "<td>". $stevt[3] ."</td>";
                           echo "<td>" . $stevt[2] ."</td>";
                           echo "<td>" . $stevt[5] ."</td>";


                        ?>

                        <?php   
                           echo "</tr> ";
                        }

                 }  
              echo "</tbody>
           </table>";
             ?>




// my bootstrap modal :-


<div id="thisdiv" class="modal fade" role="dialog">
                <div class="modal-dialog">

                  <!-- Modal content-->
                  <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>

                            <div class="row">
                                <div class="col-sm-12">
                                    <?php
                                        $trdet= mysqli_query($con, "select * from t_tevent where e_id= 'EVT0005'");
                                        while($tdet = mysqli_fetch_array($trdet))              
                                         {
                                     ?>
                                </div>
                            </div>
                            <h4 class="modal-title"><?php echo $tdet[1];  ?></h4>

                        </div>

                        <div class="modal-body">

                            <div class="row">
                                <div class="col-sm-6">
                                    <font style="color: #999999 ;  font-family:Verdana; font-weight: bold;">
                                        <strong>Venue:  </strong> 
                                    </font>

                                    <font style="  font-family:Verdana; font-weight: normal;">
                                            <?php echo $tdet[2];?>
                                    </font>
                                </div>

                                <div class="col-sm-6">     
                                    <font style="color: #999999 ;  font-family:Verdana; font-weight: bold;">
                                        <strong>Date:  </strong> 
                                    </font>

                                    <font style=" font-family:Verdana; font-weight: normal;">
                                            <?php echo $tdet[3];?>
                                    </font>

                              </div>
                            </div>

                             <div class="row" style="margin-top:14px;">
                                   <div class="col-sm-12">
                                       <font style="color: #999999 ;  font-family:Verdana; font-weight: bold;">
                                           <strong>Details:  </strong>
                                       </font>

                                       <p style="color: black;font-family:Verdana; font-weight: normal;margin-top:4px;margin-left:14px;">
                                               <?php echo $tdet[4];?>
                                       </p>
                                   </div>
                            </div>


                            <div class="row">
                               <div class="col-sm-12">
                                   <font style="color: #999999 ;  font-family:Verdana; font-weight: bold">
                                       <strong>Uploaded By </strong>
                                   </font>

                                   <font style="  font-family:Verdana; font-weight: normal;">
                                      <?php 
                                           $ctdname = mysqli_query($con, "select f_name from t_faculty where f_email='" . $tdet[6] ."'");
                                           $ctname = mysqli_fetch_assoc($ctdname);
                                           $ctshow    = $ctname["f_name"];

                                           echo $ctshow ;

                                       ?>
                                   </font>

                                   <font style="color: #999999 ;  font-family:Verdana; font-weight: bold">
                                       <strong>On </strong>
                                   </font>     

                                   <font style="font-family:Verdana; font-weight: normal;">
                                       <?php echo $tdet[5];  
                                           } 
                                       ?>
                                   </font>
                               </div>
                           </div>

                        </div>

                        <div class="modal-footer">

                              <input type="submit" name="stpart" value="Participate" style="margin-left: 100px;">   

                        </div>
                   </div>

                </div>
              </div>

1 个答案:

答案 0 :(得分:0)

如果你想根据你在url中传递的值在模态或页面中获取特定值,那么你必须在ahref标签中设置变量,这将导致这个页面

您必须使用url动态导出表行,该url将获取将数据传递到下一页的ID

//I have defined the primary key column name as uid to fetch data
$sql="SELECT * from table;"
$result="$conn->query($sql)";
while{
$row=mysqli_fetch_assoc($result) ;
echo'<tr>
     <td>'.$row['columname'].''</td>
     <td> <a href="www.mysite.com/mypage.html?id=".$row['uid'].">EDIT</a></td>
     </tr>'
}

现在在您希望选择数据的第二页

if isset($GET_['id']){
$id="$GET_['id']";
//The select function
$sql="SELECT * from WHERE id=$id";
$result= $conn->query($sql);
while{$row=mysqli_fetch_assoc($result)}
//write the html that you want generated with dynamic values
echo'<tr><td>'.$row['name'].'</td><td>'.$row['gender'].'</td></tr>'
}

我希望这可以帮助你随时写信给我anish.thuruthiyath(at)outlook(dot)com