如何在点击链接的同一页面上调用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>

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.

HTML frames are used to solved your problem, whice is user to divide your browser window into multiple sections where each section can load a separate HTML document. A collection of frames in the browser window is known as a frameset. The window is divided into frames in a similar way the tables are organized: into rows and columns.

So you try to use Frame concept Instead writing more than one html tag within one page.

<!DOCTYPE html>
 <html>
     <head>
       <title>HTML Frames</title>
     </head>
  <frameset rows="10%,80%,10%">
        <frame name="top" src="abc.html" />
        <frame name="main" src="xyz.html" />
        <frame name="bottom" src="abcd.html" />
    <noframes>
      <body>
        Your browser does not support frames.
      </body>
    </noframes>
  </frameset>
 </html>

The above example to create three horizontal frames.

If you want to create all the frames vertically, change the line as

<frameset cols="25%,50%,25%">