PHP如果选择此选项,请执行此操作

时间:2012-05-25 19:05:56

标签: php mysql

我有一个非常简单的IF声明,一周前对我有用,但现在神秘地对我不起作用。我选择了一个字段,创建一个额外的查询。

问题是,doc完全跳过我的if语句,就像它甚至不存在一样

这是整个代码

<body id="bdy" onload="javascript:fg_hideform('fg_formContainer','fg_backgroundpopup');">
        <div class="container_22" id="container">
            <div id="rootDiv">
                <div style="background-color: rgb(255, 255, 255);"
                id="wrapper">
                    <div class="main">
                        <div id="mainMiddle" class="main-middle">
                            <div id="content" class="wide-content"
                            style="position: relative; width: 990px; background-color: rgb(255, 255, 255);

                            display: inline; margin-left:

                            15px;">
                                <span id="cntntMiddle_bannerTop"></span><!-- =search-bar | start -->
                                <div id="cntntMiddle_SearchBoxContainer"
                                style="margin-top: 20px; padding-left: 20px;">
                                    <form action="search.php" class="search-bar" method="GET">
                                        <h3>Search</h3>
                                        <fieldset>
                                            <div class="ctrlHolder inline">
                                                <input type="checkbox" name="r" id="r" value="y">
                                                Return Flight?
                                            </div>
                                            <div class="ctrlHolder

                                            inline">
                                                <input type="hidden" class="fnc-direction" id="curusd" name="Currency" value="USD"  /> </div>    <div id="trip-1" class="fnc-trip first">      <h6 ><span id="flight1">Departing Flight</span>  </h6>  <div

class="ctrlHolder"> <label for="from-1">  <span class="left">From</span> <span class="right">(City or Airport)</span> </label>  <?php
    $autocomplete1 = array();
    mysql_connect('localhost', '', ''); 
    mysql_select_db('');
    $sql = "SELECT distinct rout_from FROM search_v ORDER BY rout_from ASC";
    $r = mysql_query($sql);
    while ($row = mysql_fetch_array($r))
{
      $autocomplete1[] = $row['rout_from'];
    }
?><input id="newsearch1" name="departure_label">

</div>  <div class="ctrlHolder"><label for="from-1">  <span class="left">To</span> <span class="right">(City or Airport)</span> </label>  <?php
    $autocomplete = array();
    mysql_connect('localhost', '', ''); 
    mysql_select_db('');
    $sql = "SELECT distinct rout_to FROM search_v ORDER BY rout_to ASC";
    $r = mysql_query($sql);
    while ($row = mysql_fetch_array($r))
{
      $autocomplete[] = $row['rout_to'];
    }
?><input id="newsearch" name="arrival_label"> </div>  <div class="ctrlHolder"> <label for="leave-1">Depart</label>  

<input type="text" id="f" name="txtDate1"/> </div> <div class="ctrlHolder"> <label for="leave-2">Arrive</label>  

<input type="text" id="t" name="txtDate2"/></div>  </div>  </fieldset> <fieldset class="travelers">

<legend>Travelers
                                            </legend>
                                            <div class="ctrlHolder inline-select clearfix">
                                                <div class="field">
                                                    <label for="adults">
                                                        <br />
                                                        Passengers</label>
                                                    <select

                                                    name="ddlPAxADT" id="ddlPaxADT">
                                                        <option selected="selected"

                                                        value="1">1</option><option value="2">2</option><option

                                                        value="3">3</option><option value="4">4</option><option value="5">5</option>
                                                    </select>
                                                </div>
                                                <br>
                                            </div>
                                        </fieldset>
                                        <div class="submit-wrap

                                        clearfix">
                                            <button class="btn-reset" type="reset">
                                                Reset
                                            </button>
                                            <input

                                            name="submit" class="btn-search" type="submit" />
                                        </div>
                                    </form>
                                </div>
                                <div id="cntntMiddle_search-results" class="search-results">
                                    <span id="cntntMiddle_lblResults"> <h2>Search Results</h2> <h3>Showing <span id="cntntMiddle_ctl01_lblFlightFilter">all
                                            results</span></h3> 
        <?php
mysql_connect('localhost', '', ''); 
mysql_select_db(''); 

                                        $search = $_GET['search'];
                                        $sfrom = $_GET['departure_label'];
                                        $sto = $_GET['arrival_label'];
                                        $sfromda = $_GET['txtDate1'];
                                        $stoda = $_GET['txtDate2'];
                                        $padt = $_GET['ddlPaxADT'];
                                        $currency = $_GET['Currency'];
                                        $ret = $_GET['r'];
                                        if ($ret!='y') {
                                        $sql1 = mysql_query("SELECT * FROM search_v WHERE rout_to='$sfrom' AND rout_from='$sto' AND date_avialable='$stoda'") or die(mysql_error());
                                        $runrows1 = mysql_fetch_array($sql1);
                                        $flightid1 = $runrows1['flight_id'];
                                        $aseats1 = $runrows1['seats_avialable'];
                                        $todate1 = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows1['to_date']));
                                        $date1 = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows1['date_avialable']));
                                        $from1 = $runrows1['rout_from'];
                                        $to1 = $runrows1['rout_to'];
                                        $acost1 = $runrows1['adult_cost'];
                                        $ccost1 = $runrows1['child_cost'];
                                        $cur1 = $runrows1['currency'];
                                        $oth1 = $runrows1['other_cost'];
                                        $totalcost1= $acost1+$oth1;
                                        $pr1 = $flightid1+5;

                                        }
                                        //echo outconstruct
                                        $sql = mysql_query("SELECT * FROM search_v WHERE currency='$currency' AND

                                        rout_to='$sto' AND rout_from='$sfrom' AND DATE_FORMAT(date_avialable,'%Y-%m-%d')

                                        between'".$sfromda."' and '".$stoda."' LIMIT 10") or die(mysql_error()) ;
                                        while ( $runrows = mysql_fetch_array($sql))
                                        {

                                        //get data
                                        $flightid = $runrows['flight_id'];
                                        $aseats = $runrows['seats_avialable'];
                                        $todate = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows['to_date']));
                                        $date = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows['date_avialable']));
                                        $from = $runrows['rout_from'];
                                        $to = $runrows['rout_to'];
                                        $acost = $runrows['adult_cost'];
                                        $ccost = $runrows['child_cost'];
                                        $cur = $runrows['currency'];
                                        $oth = $runrows['other_cost'];
                                        $totalcost= $acost+$oth;
                                        $pr = $flightid+5;
                                        echo "";
                                        ?>
<?PHP
include('popup/contactform-code.php');
?>
                                        <ul class="result-list clearfix">
                                            <li class="item clearfix">
                                                <span
                                                id="cntntMiddle_ctl01_rptmain_lblFromt_0">
                                                    <table cellpadding="0" cellspacing="0">
                                                        <thead>
                                                            <tr>
                                                                <th class="price">Price<?php echo $ret; ?></th>
                                                                <th>From</th>
                                                                <th>To</th>
                                                                <th>Depart</th>
                                                            </tr>
                                                        </thead>
                                                        <tfoot>
                                                            <tr>

                                                                <td colspan="6">
                                                                <div class="select-wrap">
                                                                    <p class="seats">
                                                                        <strong><?php echo $aseats; ?></strong><span>seats
                                                                            left</span><em>at this price</em>
                                                                    </p>                                                                <a href='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");'
><img border='0' src='images/select_flight.png' width='121' height='34' /></a>
                                                                </div></td>
                                                            </tr>
                                                        </tfoot>
                                                        <tbody>
                                                            <tr>
                                                                <td class="price" rowspan="2"><a
                                                                style="font-weight: bold; cursor: pointer; text-decoration: none;"
                                                                herf="#" onclick='return ray.ajax("#");'><span
                                                                style="font-size: 24px; font-weight: bold;"><?php echo $totalcost; ?></span><span
                                                                style="font-size: 11px; margin-top: 2px; display: block; color: rgb(255, 255,

                                                                255); text-align: center; font-

                                                                weight: normal;">per
                                                                    person</span><span
                                                                style="font-size: 12px; margin-top: 2px; display: block; color: rgb(255, 255,

                                                                255); text-align: center; font-

                                                                weight: normal;">(with fees)</span></a></td>
                                                                <td><?php echo $from; ?></td>
                                                                <td><?php echo $to ?></td>
                                                                <td style="padding-right: 2px;"><?php echo $date; ?></td>
                                                            </tr>
                                                            <tr>
                                                                <td><?php echo $to1; ?></td>
                                                                <td><?php echo $from1 ?></td>
                                                                <td style="padding-right: 2px;"><?php echo $date1; ?></td>
                                                            </tr>
                                                        </tbody>
                                                    </table> </span><a
                                                id="cntntMiddle_ctl01_rptmain_lblResultDetails1_0" title="1"
                                                href="javascript:__doPostBack('ctl00$cntntMiddle$ctl01$rptmain

                                                $ctl00$lblResultDetails1','')"
                                                style="color: Black;"></a><a class="close"
                                                href="#">Close</a>
                                                <div class="info clearfix">
                                                    <div class="info clearfix">
                                                        <h4>Departing Flight</h4>
                                                        <ul class="clearfix">
                                                            <li>
                                                                <h5><?php echo $from; ?> to <?php echo $to; ?> <?php echo $date; ?></h5>
                                                                <ul>
                                                                    <li>
                                                                        &nbsp;
                                                                    </li>
                                                                    <li>
                                                                        <strong>Flight #</strong> - <?php echo $flightid; ?>
                                                                    </li>
                                                                    <li>
                                                                        <strong>Departure Time – </strong>
                                                                        <?php echo $date; ?>
                                                                    </li>
                                                                </ul>
                                                            </li>
                                                        </ul>
                                                        <ul>
                                                            <li style="padding-top: 5px;">
                                                                <span
                                                                style="color: rgb(212, 22, 13); font-weight: bold; font-size: 11px; text-

                                                                decoration: none;"> Fare Breakdown</span>
                                                            </li>
                                                        </ul>
                                                        <table class="more">
                                                            <tbody>
                                                                <tr>
                                                                    <th>Passenger</th>
                                                                    <th>Fare</th>
                                                                    <th> Taxes and Fees</th>
                                                                    <th>Qty</th>
                                                                    <th>Total Cost</th>
                                                                </tr>
                                                            </tbody>
                                                            <tbody>
                                                                <tr>
                                                                    <td>Adult</td>
                                                                    <td
                                                                    style="color: rgb(100, 100, 100); font-size: 11px; font-weight: bold;"><?php

                                                                    echo $acost; ?></td>
                                                                    <td><?php echo $oth; ?></td>
                                                                    <td id="paxAdtTd">1</td>
                                                                    <td><?php echo $acost; ?></td>
                                                                </tr>
                                                                <tr>
                                                                    <td>&nbsp;</td>
                                                                    <td>&nbsp;</td>
                                                                    <td>Cost of Sale(<?php echo $cur; ?>)</td>
                                                                    <td>&nbsp;</td>
                                                                    <td
                                                                    style="color: rgb(100, 100, 100); font-size: 14px; font-weight: bold;"><?php

                                                                    echo $totalcost; ?></td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                        <br />
                                                        <span style="font-weight: bold; padding-top: 10px;"> *Additional airline fees for baggage may apply</span>
                                                        <div class="select-wrap">
                                                            <p class="seats">
                                                                <strong><?php echo $aseats; ?></strong><span>seats
                                                                    left</span><em>at this price</em>
                                                            </p>
                                                            <button class="btn-select" type="button" id="start">
                                                                Select
                                                                Flight
                                                            </button>
                                                        </div>
                                            </li>
                                        </ul> </ul>
                                        </ul>
                                         <?php ;}?>
                                </div>
                            </div>

2 个答案:

答案 0 :(得分:0)

我认为这是因为尾随换行符。因此,在您实际执行if($ret != 'y')之前,只需修剪它$ret = trim($ret)。试一试。

$ret = $_GET['r'];
$ret = trim($ret);
if ($ret!='y') 
 {
   // rest of your code
 }

答案 1 :(得分:0)

尝试类似:

<?php
    $ret = $_GET['r'];
    if($ret != "y") {
        echo "Yay!";
    } else {
        echo ":(";
    }
?>
<html>
    <head>

    </head>

    <body>
        <form method="get" action="search.php">
             <input type="checkbox" value="y" name="r" />Submit Query<br />
             <input type="submit" value="Submit" name="submit" />
        </form>

    </body>
</html>