douyan1453 2019-01-04 06:50
浏览 39

显示点击的详细信息

In my project, I have 3 tables - Survey, survey Questions, Survey options. In the survey table, it stores the survey names. In survey questions table store the questions to the respective survey. In the survey options table store the options of each question. Now I've displayed the survey names in a table. Here my problem is, When I click any survey name, it should display the corresponding questions of survey and options of that questions. for example, in the page, the survey names displayed like below 1. ABC survey 2. ERG survey

When I click on the ABC survey, it should display all questions and options related to that survey. I'm new to PHP coding. I'm using PHP, MySQL with XAMPP server. I did up to display the survey names.Below is my code

 <tr><th>Name</th><th>Created Date</th><th>Status</th></tr>
    <?php   
    $sql=mysqli_query($connection,"select * from survey"); 
    if(mysqli_num_rows($sql)==0) 
    { 
    echo "No records to display";
     }
     else {
     while($row=mysqli_fetch_array($sql)) {
     echo "<tr><td><a href='surveydetails.php' name='selected_survey_$i' 
    id='selected_survey'>".$row['survey_name']."</td><td>" .$row['created_date'] 
    ."</td>"; echo "<td>";
    if($row['status']==1){
    echo "<select name='status'>
    <option value='1' selected='selected'>Active</option>
    <option value='0'>Inactive</option>                                  
    </select>";
    }
    else{
    echo "<select name='status'>
    <option value='1'>Active</option>
    <option value='0' selected='selected'>Inactive</option></select>";
    }
    echo "</td></tr>";
    $i++;
    }
} 
?>
  • 写回答

1条回答 默认 最新

  • dqask02082 2019-01-04 09:06
    关注

    Below are different way to achieve

    1. Write javascript onClick function on in Name with survey id.Call AJAX request using javascript and fetch data from database regarding both table like question/answer. Show data into window popup screen (AJAX response data show in popup).

    2. Write javascript onClick function on in Name with survey id.Call AJAX request and retrieve information from database and show into popup box. Information will show in fancy look, if you use bootstrap.(You can use bootstrap modal box.) Refer good example here Bootstrap 3 - How to load content in modal body via AJAX?

    Bootstrap: List data showing into Table. Providing link to view more Detail Call AJAX request to retrieve data from back end Refer Below sample code:

    /*Test. PHP file*/
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <table class="table table-striped table-bordered" style="width:100px;" id="sample">
        <tr>
            <th>Name</th>
        </tr>
    
        <tr>
            <td><button id="3" class="viewDetail">Surya</button></td>
        </tr>
    
        <tr>
            <td><button id="2" class="viewDetail">ABCD</button></td>
        </tr>
    
    </table>
    
    <!-- Modal -->
    <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">
    
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">×</button>
                    <h4 class="modal-title">Content</h4>
                </div>
    
                <div class="modal-body" id="contentBody">
    
                </div>
    
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
    
        </div>
    </div>
    
    <script>
        $(document).ready(function () {
            $('#sample').on('click', '.viewDetail', function (e) {
                var id = $(this).attr('id');
                $.ajax({
                    type: "POST",
                    url: "getDetail.php?id=" + id,
                    data: {id: id}
                }).done(function (data) {
                    $("#contentBody").html(data);
                    $('#myModal').modal({show: true});
                });
            });
        });
    </script>
    
    
    
    
    /*Second File : getDetail.php*/
    <?php
    $id = $_REQUEST['id'];
    echo "Receive data from backend for ID ".$id;
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么