dpgjci27392 2015-09-16 05:36
浏览 10
已采纳

如何在点击链接的同一页面上调用php文件[关闭]

i am new to php & would like to call another php file on the same file in the div tag. on the home page i am calling the php file & have link on those files & want to open the result of that link below in the div tag. I want to dispaly the result of all the links in the div tag

Please Help !

Thanks in advance

ViewBdd.php

<html>
    <body>
    <table align="center" width="100%">
        <tr>
            <td>
                <?php
                $con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
                mysqli_select_db($con,"csdata");
                $result = mysqli_query($con,"SELECT *
              FROM `data`");

                echo "<table border='1' cellpadding='5' cellspacing='2' style='border:black; ' align='center'>
                            <tr><th colspan='4'>(BDD-2015)</th></tr>
                            <tr>
                                <th id='td'>Customer Name</th>  
                                <th id='td'>Rs. in Lakhs</th>
                                <th id='td'>Metric Ton</th>
                                <th id='td'>Percentage</th>
                            </tr>";
                while($row = mysqli_fetch_array($result))
                {
                    echo "<tr>";
                    echo "<td align='center' id='td'><a href='sku.php?Customer_name=" . $row['Customer_name'] . "'>" . $row['Customer_name'] . "</a></td>";
                    echo "<td align='center' id='td'>" . round($row['Total'],2) . "</td>";
                    echo "<td align='center' id='td'>" . round($row['MT'],2) . "</td>";
                    echo "<td align='center' id='td'>" . round($row['Percentage'],2) . "</td>";
                    echo "</tr>";
                }
                echo "</table>";
                mysqli_close($con);
                ?></td>
        </tr>
    </table>
    </body>
</html>

sku.php

<html>
    <body>
    <table align="center" width="100%">
        <tr>
            <td>
                <?php
                $con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
                mysqli_select_db($con,"csdata");
                $name=$_GET['Customer_name'];
                $result = mysqli_query($con,"Select * from `data` ");

                echo "<table border='1' cellpadding='5' cellspacing='2' style='border:black; ' align='center'>
                            <tr>
                                <th id='td'>Customer Name</th>
                                <th id='td'>Item Name</th>
                                <th id='td'>Rs. in Lakhs</th>
                                <th id='td'>Metric Ton</th>
                            </tr>";
                while($row = mysqli_fetch_array($result))
                {
                    echo "<tr>";

                    echo "<td align='center' id='td'>" . $row['Customer_Name'] . "</td>";
                    echo "<td align='center' id='td'>" . $row['Item_Grouping'] . "</td>";
                    echo "<td align='center' id='td'>" . round($row['Amount'],2) . "</td>";
                    echo "<td align='center' id='td'>" . round($row['MT'],2) . "</td>";
                    echo "</tr>";
                }
                echo "</table>";
                mysqli_close($con);
                ?></td>
        </tr>
    </table>
    </body>
</html>
  • 写回答

2条回答 默认 最新

  • duanruoyu6675 2015-09-16 05:57
    关注

    In order to call another PHP script without refreshing a page you have to use AJAX

    1. Look throught this tutorial http://www.w3schools.com/php/php_ajax_intro.asp
    2. Easiest way to use AJAX (imho) is usage of jQuery. Here is another tutorial http://www.w3schools.com/jquery/default.asp

    As for your code:

    1. You have to place a link inside you div's
    2. Attach an event listener to all these links
    3. Call an AJAX request inside this event listener
    4. Render output result of AJAX request into your html

    Some changes to your code:

    1. Instead of

    use

    <div class="sales"><a href="SalesBdd.php" class="get_result"></a></div>
    
    1. Then add

      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
      

    to home.php

    1. Then add to home.php script

      $('.get_result').click(function (event) 
      { 
         event.preventDefault(); 
      
         var url = $(this).attr('href');
         $.get(url, function(data) {
            $('.sales').html(data);
         });
      });
      

    As a result then you press link, the resulting html (which is get from php page) will be placed instead of link into div.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图