如何在PHP中划分网页?

This is my code:

<?php
function GetDays($sStartDate, $sEndDate){   
  $sStartDate = gmdate("Y-m-d", strtotime($sStartDate));   
  $sEndDate = gmdate("Y-m-d", strtotime($sEndDate));   

  $aDays[] = $sStartDate;   
  $sCurrentDate = $sStartDate;   
  while($sCurrentDate < $sEndDate){   
     $sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));   
      $aDays[] = $sCurrentDate;   
  }   
    return $aDays;   
}  
?>

<html>
<head>
<script language="JavaScript" src="calendar_us.js"></script>

    <link rel="stylesheet" href="calendar.css">
</head>

<body background="mainbg.JPG">  
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?
//If we submitted the form
if(isset($_POST['submitMe']))
{  
$sec=00;
$sc=00;
$name=$_POST['name'];
 $mm=substr($_POST['testinput'],0,2);
 $dd=substr($_POST['testinput'],3,2);
 $yy=substr($_POST['testinput'],6,4);
 $sdate = $yy."-".$mm."-".$dd; 

 $mn=substr($_POST['test'],0,2);
 $dn=substr($_POST['test'],3,2);
 $yn=substr($_POST['test'],6,4);
 $edate = $yn."-".$mn."-".$dn;

$host="10.207.100.10";// Host name
$username="root";// Mysql username
$password="######"; // Mysql password
$db_name="wtems"; // Database name
$tbl_name="constellation_reserve"; // Table name // Connect to server and selectdatabse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM constellation_reserve where CID=$name and (start_date between '$sdate' and '$edate' or end_date between '$sdate' and '$edate')";
$result=mysql_query($sql); // Define$color=1
if($result)
    {
$color="1"; 
echo '<table border="0" cellpadding="8" align="center">';
 echo'<tr>';
      echo'</tr>';
       echo'<tr>';
      echo'</tr>';
    echo '<tr><h3 align="center"<font color="white">RESERVATION </font></h3></tr>';
     echo'<tr>';
      echo'</tr>';
     echo'<tr>';
echo '<table width="500" height="300" border="0" align="center" cellpadding="8" cellspacing="2">';
$fields_num = mysql_num_fields($result);
    echo "<tr bgcolor='#0099FF'>";
    echo "<td><FONT COLOR='FFFFFF'>ID</FONT> </td>";
    echo "<td><FONT COLOR='FFFFFF'>START DATE</FONT></td>";
    echo "<td> <FONT COLOR='FFFFFF'>RESERVED BY </FONT></td>";
    echo "<td><FONT COLOR='FFFFFF'>END DATE</FONT></td>";


    echo "</tr>
";
while($rows=mysql_fetch_array($result))
    { // If $color==1 table row color = #FFC600
    if($color==1)
    {
        echo "<tr bgcolor='#FFFFDD'>

        <td>".$rows['CID']."</td><td>".$rows['start_date']."</td><td bgcolor='#99AAFF'><FONT COLOR='FFFFFF'>".$rows['owner']."</FONT></td><td>".$rows['end_date']."</td></tr>";
        // Set$color==2, for switching to other color
        $color="2";
        } // When$color not equal 1, use this table row color
        else
        {
            echo "<tr bgcolor='#FFFFEE'><td>".$rows['CID']."</td><td>".$rows['start_date']."</td><td bgcolor='#99AAFF'><FONT COLOR='FFFFFF'>".$rows['owner']."</FONT></td><td>".$rows['end_date']."</td></tr>";// Set   $color back to 1
            $color="1";
            } 
            }
            echo '</table>';

            mysql_close();
            echo '</tr>';
            echo '</table>';
    }
    else
    {
        echo '<table border="0" cellpadding="8" align="center">';
            echo '<tr><h3 align="center"<font color="white">NoDataFound</font></h3></tr>';
            echo '</table>';
    }
    }

//If we haven't submitted the form
else
{
?>

<h3 align="center"<font color="white">REPORT DETAILS</font></h3> 
<table border="1" cellpadding="8" align="center">
<br>
</br>
<tr><td align="left">Constellation ID</td><td>:</td><td> <input type="text" name="name" /></td></tr>
<tr><td align="left">Start Date</td><td>:</td><td> <input type="text" name="testinput" />
    <script language="JavaScript">
    new tcal ({
        // form name
        //'formname': 'testform'
        // input name
        'controlname': 'testinput'
    });
    </script>


    </td></tr>
<tr><td align="left">End Date</td><td>:</td><td> <input type="text" name="test" />
    <script language="JavaScript">
    new tcal ({
        // form name
        //'formname': 'testform'
        // input name
        'controlname': 'test'
    });
    </script>


 </td></tr>

</table>

<br>
</br>

<br>
</br>
<p align="center"><input type="submit" value="REPORT" name="submitMe"></p>  
<?php
}
?> 
</form>
</body>
</html> 

when i execute the code is working fine but, the datas are not displaying in the same page. when the data are displaying the page is refreshing so i cant view the data in same page.

You should never use a root username and password when you are developing an app, create an account and use, when you post remove it.

The issue has to be coming from your JavaScript if your page refreshes after loading. PHP is a server side language, meaning it can redirect before user output but not after. Post your JS or a link to the page here so we can help more.

Seconding @ProNeticas -- NEVER ever use your root password when you are developing an app.

Also your code is open to SQL injection -- please read about mysql_real_escape_string

@user.. i just format your code... please look and apply... then we'll discuss on your problem...

<?php
    function GetDays($sStartDate, $sEndDate){   
      $sStartDate = gmdate("Y-m-d", strtotime($sStartDate));   
      $sEndDate = gmdate("Y-m-d", strtotime($sEndDate));
      $aDays[] = $sStartDate;   
      $sCurrentDate = $sStartDate;   
      while($sCurrentDate < $sEndDate){   
         $sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));   
          $aDays[] = $sCurrentDate;   
      }   
        return $aDays;   
    }  
?>
<html>
<head>
    <script type="javascript" src="calendar_us.js"></script>
    <link rel="stylesheet" href="calendar.css" >
</head>
<body background="mainbg.JPG">  
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?
//If we submitted the form
if(isset($_POST['submitMe']))
{  
    $sec=00;
    $sc=00;
    $name=$_POST['name'];
    $mm=substr($_POST['testinput'],0,2);
    $dd=substr($_POST['testinput'],3,2);
    $yy=substr($_POST['testinput'],6,4);
    $sdate = $yy."-".$mm."-".$dd; 

    $mn=substr($_POST['test'],0,2);
    $dn=substr($_POST['test'],3,2);
    $yn=substr($_POST['test'],6,4);
    $edate = $yn."-".$mn."-".$dn;

    $host="#######";// Host name
    $username="#####";// Mysql username
    $password="######"; // Mysql password
    $db_name="####"; // Database name
    $tbl_name="constellation_reserve"; // Table name // Connect to server and selectdatabse
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql="SELECT * FROM constellation_reserve where CID=$name and (start_date between '$sdate' and '$edate' or end_date between '$sdate' and '$edate')";
    $result=mysql_query($sql); // Define$color=1
    $fields_num = mysql_num_fields($result);
    if($result)
    { ?>
        <table border="0" cellpadding="8" cellspacing="5" align="center">
            <tr>
                <td><h3 align="center"<font color="white">RESERVATION </font></h3></td>
            </tr>           
            <tr>
                <td>
                    <table width="500" height="300" border="0" align="center" cellpadding="8" cellspacing="2">              
                    <tr style="color:#fff;background-color:#0099FF">
                        <td>ID</td>
                        <td>START DATE</td>
                        <td>RESERVED BY</td>
                        <td>END DATE</td>
                    </tr>
<?php
            while($rows=mysql_fetch_array($result))
            { $color=1;
                // If $color==1 table row color = #FFC600
              if($color == 1){ ?>
                    <tr background-color='#FFFFDD'>
                        <td><?php echo $rows['CID']?></td>
                        <td><?php echo $rows['start_date'];?></td>
                        <td style="color:#FFF;background-color:#99AAFF'><?php echo $rows['owner'];?></td>
                        <td><?php echo $rows['end_date']?></td>
                    </tr>
            <?php  $color=2;
                } else { ?>
                    <tr background-color='#FFFFEE'>
                        <td><?php echo $rows['CID'];?></td>
                        <td><?php echo $rows['start_date'];?></td>
                        <td style="color:#FFF;background-color:#99AAFF'><?php echo $rows['owner'];</td>
                        <td><?php echo $rows['end_date'];?></td>
                    </tr>
           <?php  $color=1;
                } 
            } ?>
                    </table>
<?php     mysql_close(); ?>
                </td>
            </tr>
        </table>
<?php   }  else { ?>
        <table border="0" cellpadding="8" align="center">
            <tr><h3 align="center"style="color:#fff">NoDataFound</h3></tr>
        </table>
<?php   }
} //If we haven't submitted the form
else { ?>
<h3 align="center"<font color="white">REPORT DETAILS</font></h3> 
<table border="1" cellpadding="8" align="center">
    <tr>
        <td align="left">Constellation ID</td>
        <td>:</td>
        <td> <input type="text" name="name" /></td>
    </tr>
    <tr>
        <td align="left">Start Date</td>
        <td>:</td>
        <td> <input type="text" name="testinput" />         
        <script type="javascript">
        new tcal ({
            // form name
            //'formname': 'testform'
            // input name
            'controlname': 'testinput'
        });
        </script>
            </td>
    </tr>
    <tr>
        <td align="left">End Date</td>
        <td>:</td>
        <td> <input type="text" name="test" />
        <script typr"javascript">
        new tcal ({
            // form name
            //'formname': 'testform'
            // input name
            'controlname': 'test'
        });     
        </script>
            </td>
    </tr>
</table>
<p align="center"><input type="submit" value="REPORT" name="submitMe"></p>  
<?php } ?> 
</form>
</body>
</html>