English 中文(简体)
如果选中此选项, 请这样做 PHP PHP
原标题:PHP If this option is selected, do this
  • 时间:2012-05-25 19:05:56
  •  标签:
  • php
  • mysql

我有一个非常简单的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>
问题回答

我认为这是因为新行字符的尾行。 所以, 在您实际做 < code> if( $ret! = y) 之前, 请先修改 < code> $ret = term( $ret) 。 尝试一下 。

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

尝试一些东西,比如:

<?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>




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签