0

我在侧边栏上有一个 PHP 语句,侧边栏包含在所有页面上。在边栏中,我想在结果页面上隐藏内容,所以我使用这个:

<?php
if ($page!='results')
{?>
<h1>THE MAIN SIDEBAR CONTENT</h1>
<div>
SOME CONTENT          
</div>
<?php }  ?>

问题是它看起来没有将页面识别为

$page='results';

在它的顶部。也许是因为代码在包含的页面中,但我认为它只会被读为一页?

如果我添加

$page='results';

在上述脚本的开头,它可以工作(只是为了验证我是否正确编写了代码。

我还检查了 results.php 有

$page='results';

就在它的最顶端。

我不能在包含上使用此代码还是我遗漏了什么?

根据 navnav 的要求,这里是包含和实际页面的代码。注意我实际上并没有使用'$results',我只是用它作为我的帖子的一个例子。在下面的真实代码中,你会看到我正在使用 '$getvaluation'

侧边栏代码....

<div class="right_part right_home">
      <h1 style="padding-left: 25px">Property <span>Search</span></h1>

      <script type="text/javascript">
          $('#couHertfordshire').click(function(){
            var v = $(this).val();
            $('#couHertfordshire_hide').val(v);
          });
           $('#couLondonNorth').click(function(){
            var v = $(this).val();
            $('#couLondonNorth_hide').val(v);
          });
           $('#couLondonNorthWest').click(function(){
            var v = $(this).val();
            $('#couLondonNorthWest_hide').val(v);
          });
      </script>

      <?php
            $page = $_SERVER['REQUEST_URI'];
            $page = explode('/', $page);
        if (isset($_POST['bed']) && $_POST['bed'] != '' && $page[2] == 'test.php'){
            $url = 'http://www.vebra.com/home/quick/PFrefine.asp';
            $target = 'target="hello"';
            $js_submit = true;                  

            $bed = $_POST['bed'];
            $min = $_POST['lop'];
            $max = $_POST['hip'];
            $area1 = $_POST['cou1'];
            $area2 = $_POST['cou2'];
            $area3 = $_POST['cou3'];
            // Hidden Fields
            $hidden1 = $_POST['slo'];
            $hidden2 = $_POST['fid'];
            $hidden3 = $_POST['bid'];
            $hidden4 = $_POST['dbt'];
            $hidden5 = $_POST['nre'];
            $hidden6 = $_POST['thu'];
            $hidden7 = $_POST['vto'];
            $hidden8 = $_POST['ord'];
            $hidden9 = $_POST['nba'];

        } else {

            $url = 'test.php';
            $target = '';
            $js_submit = false;
        }           

      ?>

      <form method="post" action="<?php echo $url; ?>" name="searchform" id="searchform" <?php echo $target; ?> >
        <dl id="property_search">
          <dt class="bord">Bedrooms</dt>
          <dd><select name="bed" class="type1 Selectrooms">
                  <option <?php if($bed == '0'){ echo 'selected="selected"';} ?> value="0">0</option>
                  <option <?php if($bed == '1'){ echo 'selected="selected"';} ?> value="1">1</option>
                  <option <?php if($bed == '2'){ echo 'selected="selected"';} ?> value="2">2</option>
                  <option <?php if($bed == '3'){ echo 'selected="selected"';} ?> value="3">3</option>
                  <option <?php if($bed == '4'){ echo 'selected="selected"';} ?> value="4">4</option>
                  <option <?php if($bed == '5'){ echo 'selected="selected"';} ?> value="5">5+</option>
              </select>
          </dd>

          <dt class="bord">Minimum Price</dt>
          <dd><select class="type2 SelectPrices" name="lop">
                <option <?php if ($min == '0'){ echo 'selected="selected"';} ?> value="0">&#163;0</option>
                <option <?php if ($min == '25000'){ echo 'selected="selected"';} ?> value="25000">&#163;25,000</option>
                <option <?php if ($min == '50000'){ echo 'selected="selected"';} ?> value="50000">&#163;50,000</option>
                <option <?php if ($min == '75000'){ echo 'selected="selected"';} ?> value="75000">&#163;75,000</option>
                <option <?php if ($min == '100000'){ echo 'selected="selected"';} ?> value="100000">&#163;100,000</option>
                <option <?php if ($min == '125000'){ echo 'selected="selected"';} ?> value="125000">&#163;125,000</option>
                <option <?php if ($min == '150000'){ echo 'selected="selected"';} ?> value="150000">&#163;150,000</option>
                <option <?php if ($min == '175000'){ echo 'selected="selected"';} ?> value="175000">&#163;175,000</option>
                <option <?php if ($min == '200000'){ echo 'selected="selected"';} ?> value="200000">&#163;200,000</option>
                <option <?php if ($min == '225000'){ echo 'selected="selected"';} ?> value="225000">&#163;225,000</option>
                <option <?php if ($min == '250000'){ echo 'selected="selected"';} ?> value="250000">&#163;250,000</option>
                <option <?php if ($min == '275000'){ echo 'selected="selected"';} ?> value="275000">&#163;275,000</option>
                <option <?php if ($min == '300000'){ echo 'selected="selected"';} ?> value="300000">&#163;300,000</option>
                <option <?php if ($min == '325000'){ echo 'selected="selected"';} ?> value="325000">&#163;325,000</option>
                <option <?php if ($min == '350000'){ echo 'selected="selected"';} ?> value="350000">&#163;350,000</option>
                <option <?php if ($min == '375000'){ echo 'selected="selected"';} ?> value="375000">&#163;375,000</option>
                <option <?php if ($min == '400000'){ echo 'selected="selected"';} ?> value="400000">&#163;400,000</option>
                <option <?php if ($min == '500000'){ echo 'selected="selected"';} ?> value="500000">&#163;500,000</option>
                <option <?php if ($min == '600000'){ echo 'selected="selected"';} ?> value="600000">&#163;600,000</option>
                <option <?php if ($min == '700000'){ echo 'selected="selected"';} ?> value="700000">&#163;700,000</option>
                <option <?php if ($min == '800000'){ echo 'selected="selected"';} ?> value="800000">&#163;800,000</option>
                <option <?php if ($min == '900000'){ echo 'selected="selected"';} ?> value="900000">&#163;900,000</option>
                <option <?php if ($min == '1000000'){ echo 'selected="selected"';} ?> value="1000000">&#163;1,000,000</option>
                <option <?php if ($min == '2000000'){ echo 'selected="selected"';} ?> value="2000000">&#163;2,000,000</option>
                <option <?php if ($min == '3000000'){ echo 'selected="selected"';} ?> value="3000000">&#163;3,000,000</option>
                <option <?php if ($min == '4000000'){ echo 'selected="selected"';} ?> value="4000000">&#163;4,000,000</option>
                <option <?php if ($min == '5000000'){ echo 'selected="selected"';} ?> value="5000000">&#163;5,000,000</option>
                <option <?php if ($min == '6000000'){ echo 'selected="selected"';} ?> value="6000000">&#163;6,000,000</option>
              </select>
          </dd>

          <dt class="bord">Maximum Price</dt>
          <dd><select name="hip" class="type3 SelectPrices">
                <option <?php if ($max == '25000'){ echo 'selected="selected"';} ?> value="25000"> &#163;25,000</option>
                <option <?php if ($max == '50000'){ echo 'selected="selected"';} ?> value="50000">&#163;50,000</option>
                <option <?php if ($max == '75000'){ echo 'selected="selected"';} ?> value="75000">&#163;75,000</option>
                <option <?php if ($max == '100000'){ echo 'selected="selected"';} ?> value="100000">&#163;100,000</option>
                <option <?php if ($max == '125000'){ echo 'selected="selected"';} ?> value="125000">&#163;125,000</option>
                <option <?php if ($max == '150000'){ echo 'selected="selected"';} ?> value="150000">&#163;150,000</option>
                <option <?php if ($max == '175000'){ echo 'selected="selected"';} ?> value="175000">&#163;175,000</option>
                <option <?php if ($max == '200000'){ echo 'selected="selected"';} ?> value="200000">&#163;200,000</option>
                <option <?php if ($max == '225000'){ echo 'selected="selected"';} ?> value="225000">&#163;225,000</option>
                <option <?php if ($max == '250000'){ echo 'selected="selected"';} ?> value="250000">&#163;250,000</option>
                <option <?php if ($max == '275000'){ echo 'selected="selected"';} ?> value="275000">&#163;275,000</option>
                <option <?php if ($max == '300000'){ echo 'selected="selected"';} ?> value="300000">&#163;300,000</option>
                <option <?php if ($max == '325000'){ echo 'selected="selected"';} ?> value="325000">&#163;325,000</option>
                <option <?php if ($max == '350000'){ echo 'selected="selected"';} ?> value="350000">&#163;350,000</option>
                <option <?php if ($max == '375000'){ echo 'selected="selected"';} ?> value="375000">&#163;375,000</option>
                <option <?php if ($max == '400000'){ echo 'selected="selected"';} ?> value="400000">&#163;400,000</option>
                <option <?php if ($max == '500000'){ echo 'selected="selected"';} ?> value="500000">&#163;500,000</option>
                <option <?php if ($max == '600000'){ echo 'selected="selected"';} ?> value="600000">&#163;600,000</option>
                <option <?php if ($max == '700000'){ echo 'selected="selected"';} ?> value="700000">&#163;700,000</option>
                <option <?php if ($max == '800000'){ echo 'selected="selected"';} ?> value="800000">&#163;800,000</option>
                <option <?php if ($max == '900000'){ echo 'selected="selected"';} ?> value="900000">&#163;900,000</option>
                <option <?php if ($max == '1000000'){ echo 'selected="selected"';} ?> value="1000000">&#163;1,000,000</option>
                <option <?php if ($max == '2000000'){ echo 'selected="selected"';} ?> value="2000000">&#163;2,000,000</option>
                <option <?php if ($max == '3000000'){ echo 'selected="selected"';} ?> value="3000000">&#163;3,000,000</option>
                <option <?php if ($max == '4000000'){ echo 'selected="selected"';} ?> value="4000000">&#163;4,000,000</option>
                <option <?php if ($max == '5000000'){ echo 'selected="selected"';} ?> value="5000000">&#163;5,000,000</option>
                <option <?php if ($max == '6000000'){ echo 'selected="selected"';} ?> value="6000000">&#163;6,000,000+</option>
              </select>
          </dd>
          <dt>Regions</dt><dd><img src="images/spacer.gif" alt="" /></dd>

          <dt><input <?php if( $area1 == '43' ){ echo 'checked="checked"';} ?> type="checkbox" name="cou1" id="couHertfordshire" value="43" /></dt><dd>Hertfordshire</dd>
          <dt><input <?php if( $area2 == '126' ){ echo 'checked="checked"';} ?> type="checkbox" name="cou2" id="couLondonNorth" value="126" /></dt><dd>London, North</dd>
          <dt><input <?php if( $area3 == '127' ){ echo 'checked="checked"';} ?> type="checkbox" name="cou3" id="couLondonNorthWest" value="127" /></dt><dd>London, North West</dd>

            <input type="hidden" name="cou" id="couHertfordshire_hide" value="<?php if ( $area1 == '43' ) { echo '43';} ?>" />
            <input type="hidden" name="cou" id="couLondonNorth_hide" value="<?php if ( $area2 == '126' ) { echo '126';} ?>" />
            <input type="hidden" name="cou" id="couLondonNorthWest_hide" value="<?php if ( $area3 == '127' ) { echo '127';} ?>" />

            <input type="hidden" name="slo" value="undefined" />
            <input type="hidden" name="fid" value="894" />
            <input type="hidden" name="bid" value="0" />
            <input type="hidden" name="dbt" value="1" />
            <input type="hidden" name="nre" value="undefined" />
            <input type="hidden" name="thu" value="undefined" />
            <input type="hidden" name="vto" value="undefined" />
            <input type="hidden" name="ord" value="undefined"/>
            <input type="hidden" name="nba" value="undefined" />

          <dt><input type="submit" class="search_now" value="Find Property" /></dt><dd><img src="images/spacer.gif" alt="" /></dd>
        </dl>
      </form>

      <?php if($js_submit){ ?>

        <script type="text/javascript">
            $(document).ready(function() {
                document.forms["searchform"].submit();
            });
        </script>

        <?php } ?>

      <div><a href="register.php" class="register_with_us"><img src="images/spacer.gif" alt="" /></a></div>
      <div><a href="contact.php" class="our_branches"><img src="images/spacer.gif" alt="" /></a></div>
      <div><a href="valuation.php" class="free_valuation"><img src="images/spacer.gif" alt="" /></a></div>

        <?php
        if ($page!='getvaluation')
       { ?> 
       <h1 class='bot_line'>Featured <span>Property</span></h1>
      <div>
      <?php perch_content('Featured Property Image');?>           
      </div>
      <h3><?php perch_content('Featured Property Title'); ?></h3>
     <p>
     <?php perch_content('Featured Property Description'); ?>

     </p>      
     <?php }  ?>
    </div>
     <div>

  </div>

估值页面代码

<?php 
$page='getvaluation'; 
include('perch/runtime.php'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1    /DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang='en' dir='ltr'>
<head>
<title>Squires Estates - Independent Estate Agent, London</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="css/screen.css" rel="stylesheet" type="text/css" />

<!--[if IE]>
<![if lt IE 7]>
  <script type="text/javascript" src="js/DD_belatedPNG.js"></script>
  <script type="text/javascript" src="js/ie6.js"></script>
<![endif]>
<![endif]-->

<link rel="stylesheet" href="slider/themes/default/default.css" type="text/css" media="screen" />
<link rel="stylesheet" href="slider/nivo-slider.css" type="text/css" media="screen" />

<script type="text/javascript" src="slider/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="slider/jquery.nivo.slider.js"></script>
<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider({
        controlNav: false,
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
    });
});
</script>


<script type="text/javascript">
 function blurInspection(el, text) {if (el.value == '') {el.value=text;}}
 function focusInspection(el, text) {if (el.value == text) {el.value='';}}
</script>

</head>

<body>


<div id="wrapper">

<?php include("header.php"); ?>

  <div id="content">
    <div class="left_part left_home">
      <h1 class="bot_line">Please use the form below to arrange a free valuation</span></h1>
      <?php 
      // Text Section
      //perch_content('form');?>
      <?php perch_content('Form Text');?>
    </div>
    <?php 
    include('sidebar.php');
    include('footer.php');
    ?>
4

1 回答 1

1

在进行比较之前,请确保包含分配result给的文件$page

所以,

这是不好的:

<?php
if ($page!='results')
{?>
<h1>THE MAIN SIDEBAR CONTENT</h1>
<div>
SOME CONTENT          
</div>
<?php }  
include("the-file-here-that-defines-$page");//The include line is AFTER the comparing here...which means the $page value will not be changed until after the comparing...
?>

这很好:

<?php
include("the-file-here-that-defines-$page");//the include line is BEFORE the comparing, so $page will change before, and it should all work well..
if ($page!='results')
{?>
<h1>THE MAIN SIDEBAR CONTENT</h1>
<div>
SOME CONTENT          
</div>
<?php }  

?>

编辑:

我查看了您的编辑,我最初的建议是导致问题的原因。在你的sidebar.php你有$page = explode('/', $page);它在你做之后$page='getvaluation';执行,但是你也在做你的比较sidebar.php,你也在其中重新定义$page

对此的快速解决方法是简单地使用另一个变量来表示“getvaluation”:

所以,在你的 sidebar.php 中:

if($getValuation===true){$page='getvaluation';}//check if $getValuation is true (which will will be defined in your valuation page)
        if ($page!='getvaluation')
       { ?> 
       <h1 class='bot_line'>Featured <span>Property</span></h1>
      <div>
      <?php perch_content('Featured Property Image');?>           
      </div>
      <h3><?php perch_content('Featured Property Title'); ?></h3>
     <p>
     <?php perch_content('Featured Property Description'); ?>

     </p>      
     <?php }  ?>
    </div>
     <div>

现在,在您的估值页面中:

代替:

<?php 
$page='getvaluation'; 

做这个:

<?php 
$getValuation=true; 

在其他页面(您希望侧边栏显示的页面)上,不要定义$getValuation或分配它false

于 2012-07-02T12:59:03.100 回答