Web Analytics Made Easy -
StatCounter problem with echo message on search blank return - CodingForum

Announcement

Collapse
No announcement yet.

problem with echo message on search blank return

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with echo message on search blank return

    Hi, I've got a wee issue concerning a misbehaving piece of php code. What I am trying to achieve is that when a site visitor does a search and the search comes back blank rather than just going back to the search form a message is diplayed to advise that there are no properties available for that date search range. The search form looks at the sql database and is accessing a particular part of it referred to as Abacus. What is happening is that they echo displays irrespective of whether there are search results or not - naturally, I just want it appear when there is nothing to display. Any help would be much appreciated the code for the evil page is below:

    <style type="text/css">
    <!--

    }
    .style7 {
    font-size: 14px;
    color: #FFFFFF;
    }
    .style8 {font-family: Arial, Helvetica, sans-serif}
    .style9 {font-size: 14px; font-family: Arial, Helvetica, sans-serif;}
    -->
    </style>

    <?php
    // Sep 7 2006 - [email protected] - Function to work out the total rate based on some days and an allorate list
    // $days_staying is the days client wants to stay
    // $days_all and $rates are the "day of year|rate for that day" pair (days and allorate respectively in the DB)
    function sum_rates($days_staying, $days_all, $rates)
    {
    $day_arr = explode("|", $days_all);
    $day_stay_arr = explode("|", $days_staying);
    $rate_arr = explode("|", $rates);
    $dsa_lookup = array();
    $result = 0;

    // Generate hashtable from day_stay_arr
    foreach ($day_stay_arr as $dsa) {
    $dsa_lookup[$dsa] = 1;
    }

    for ($i=0; $i < count($day_arr); $i++) {
    if (isset($dsa_lookup[$day_arr[$i]])) {
    $result += $rate_arr[$i];
    }
    }
    return $result;
    }
    ?>

    <?

    $db='cimnet_new';
    $company='Southern Sun Resorts';




    $newarrive=$arrives[0].$arrives[1];
    $newarrive=explode("/", $newarrive);
    $unixarrive=mktime (0,0,0,$newarrive[1],$newarrive[0],$newarrive[2]);

    $unixdays=$days*86400;
    $unixdepart=$unixarrive+$unixdays;

    $arrive=date("d/m/Y", $unixarrive);
    $depart=date("d/m/Y", $unixdepart);

    $numberofdays=$days;

    $textarrive=date("d/m/Y", $unixarrive);
    $textdepart=date("d/m/Y", $unixdepart);

    $unixyear=mktime (0,0,0,1,1,$newarrive[2]);
    $year=$newarrive[2];
    // take year away for dates
    $unixarrive2=$unixarrive;
    $unixdepart2=$unixdepart;
    $unixarrive=$unixarrive-$unixyear;
    $unixdepart=$unixdepart-$unixyear;
    // find day of year
    $day_number_arrive=$unixarrive/86400;
    $day_number_arrive++;
    $day_number_depart=$unixdepart/86400;
    $day_number_depart++;
    $dayssql='';

    for ($loopi=$day_number_arrive;$loopi<$day_number_depart;$loopi++){
    if ($dayssql==''){
    $loopi=sprintf ("%1.0f", $loopi);

    //echo $dayssql;
    $dayssql=$loopi;
    }else{
    $loopi=sprintf ("%1.0f", $loopi);
    //echo $dayssql;
    $dayssql=$dayssql.'|'.$loopi;
    }
    }
    // end // convert arrive deprt
    //echo $dayssql;
    if (isset ($courseid)){
    $location=$location[$courseid];
    }
    $sql1=' and venue_main.town like \'%'.$location.'%\'';

    include("double_locations.php");


    // pegasusu ***********************************************************

    $queryx = "select venue_main.hotelid, cimnet_display.pegabflag, venue_main.currency, venue_rates.rate from venue_rates, venue_main, cimnet_display where venue_main.hotelid=venue_rates.hotelid and venue_main.hotelid=cimnet_display.hotelid and cimnet_display.company='$company' and venue_rates.ratename like '%$company%' and cimnet_display.display!='0' $sql1 group by venue_main.hotelid order by cimnet_display.display desc, venue_rates.rate ";

    //echo $queryx;

    $resultx= mysql_db_query("$db", $queryx);
    while ($rx= mysql_fetch_array($resultx)) {
    $hotelidx=$rx["hotelid"];
    $pegabflagx=$rx["pegabflag"];

    if ($pegabflagx=='0'){

    $querypeg="SELECT
    venue_main.hotelid,
    venue_main.name,
    venue_main.groupname,
    venue_main.website,
    venue_main.graphic,
    venue_main.notes,
    venue_main.country,
    venue_main.kcflag,
    venue_main.terms,
    venue_main.postcode,
    venue_main.currency
    from
    venue_main
    WHERE venue_main.hotelid='$hotelidx' ";
    // echo $querypeg;
    $resultpeg= mysql_db_query("$db", $querypeg);
    while ($r= mysql_fetch_array($resultpeg)) {
    $hotelid=$r["hotelid"];
    $graphic=$r["graphic"];
    $country=$r["country"];
    $kcflag=$r["kcflag"];
    $terms=$r["terms"];
    $postcode=$r["postcode"];
    if ($country=='UNITED KINGDOM'){$country='GB';}
    if ($country=='FRANCE'){$country='FR';}
    if ($country=='France'){$country='FR';}
    if ($country=='Belgium'){$country='BE';}
    if ($country=='BELGIUM'){$country='BE';}
    if ($country=='EIRE'){$country='IE';}
    if ($country=='IRELAND'){$country='IE';}
    ?>
    <form action="index.php" method="get">
    <input type="hidden" name="content" value="process">
    <input type="hidden" name="location" value="<?//echo $location
    ?>">
    <input type="hidden" name="hotel2" value="<?echo $hotel?>">
    <input type="hidden" name="hotel" value="<? echo $r["name"]?>">
    <input type="hidden" name="arrives[0]" value="<?echo $arrives[0]?>">
    <input type="hidden" name="arrives[1]" value="<? echo $arrives[1]?>">
    <input type="hidden" name="country" value="<? echo $country?>">
    <input type="hidden" name="brand" value="All">
    <input type="hidden" name="days" value="<?echo $days?>">
    <input type="hidden" name="rooms" value="<?echo $rooms?>">
    <input type="hidden" name="roomtype" value="<?echo $roomtype?>">
    <table summary="" border="0" width=500>
    <tr>
    <td rowspan=4 valign=top>
    <?if ($graphic!=''){?>
    <img src="http://images.cimnetsolutions.com/<?echo $r["graphic"];?>" border="0">
    <?}
    else{?>
    <img src="http://images.cimnetsolutions.com/nopic.jpg" border="0">
    <?}?>
    </td>
    <td align=right><b><?echo $r["name"]?>

    <?if ($country=='GB'){?>
    <a href="http://www.multimap.com/map/browse.cgi?client=public&db=pc&addr1=&client=public&addr2=&advanced=&addr3=&pc=<?echo $postcode?>&quicksearch=tn33+9eu&cidr_client=none" target=map>Map</a></b><?}?>

    <?/*if ($country=='BE'){?>
    <a href="http://www.multimap.com/map/browse.cgi?client=public&db=pc&addr1=&client=public&addr2=&advanced=&addr3=&pc=<?echo $postcode?>&quicksearch=tn33+9eu&cidr_client=none" target=map>Map</a></b><?}*/?>

    <?if ($country=='FR'){?>
    <a href="http://www.mapquest.fr/cgi-bin/ia_find?link=btwn%2Ftwn-map_results&random=318&event=find_search&uid=u7x6hah508g7x9ha%3A25dutxuaaw&country=Great+Britain&SNV Data=&address=&city=&Zip=<?echo $postcode?>&country=France&Find+Map.x=32&Find+Map.y=11" target=map>Map</a></b><?}?>


    <?if ($kcflag=='2'){?>
    <br><img src="images/smileysparkle.gif" width="32" height="32">
    <?}?>
    </td>
    </td>
    </tr>
    <tr>

    <td align=right><? echo $r["notes"]?><br><br></td>
    </tr>
    <tr>

    <td align=right><b>
    <?$query2 = "select ratename, rate, notes from venue_rates where hotelid='$hotelid' and (ratename='Corporate rate' or ratename='Rack rate' or ratename='$company') " ;
    $result2= mysql_db_query("$db", $query2);
    while ($r2= mysql_fetch_array($result2)) { ?>
    <?echo $r2["ratename"]?> - <?echo $r2["rate"]?><br>
    <?echo $r2["notes"]?><br>
    <?}?>
    <?echo $terms?><br>
    All rates quoted are in <?echo $rx["currency"];?>

    </b></td>
    </tr>
    <tr>

    <td align=right><input type="submit" value="Rate Details"></td>
    </tr>
    </table></form>
    <table summary="" border="0" width=500>
    <tr>
    <td><hr></td>
    </tr>
    </table>

    <!-- abacus ========================================= -->
    <?
    }}

    if ($pegabflagx=='1'){

    $queryab = "SELECT abacus.*,

    venue_main.hotelid,
    venue_main.name,
    venue_main.groupname,
    venue_main.website,
    venue_main.graphic,
    venue_main.country,
    venue_main.notes,
    venue_main.kcflag,
    venue_main.terms,
    venue_main.postcode
    from abacus,
    venue_main
    WHERE abacus.year='$year' and abacus.days like '%$dayssql%'
    and venue_main.hotelid='$hotelidx' $sql2 and abacus.roomtype='$roomtype' and abacus.hotelid=venue_main.hotelid and abacus.alloname like '%$company%' group by venue_main.hotelid";

    //echo $queryab;


    $resultab= mysql_db_query("$db", $queryab);
    while ($r= mysql_fetch_array($resultab)) {
    $hotelid=$r["hotelid"];
    $allono=$r["allo"];
    $day=$r["days"];
    $year=$r["year"];
    $country=$r["country"];
    $kcflag=$r["kcflag"];
    $terms=$r["terms"];
    $postcode=$r["postcode"];
    $day=explode("|",$day);
    $allono=explode("|",$allono);
    $allorate=explode("|",$allorate);
    $allonor=array();
    $acount=count($day);
    //create the keys
    $allonop = array();
    $acount=count($day);
    for ($loopi=0;$loopi<$acount;$loopi++){
    $temparray=array($day[$loopi] => $allono[$loopi]);
    $allonop=$allonop+$temparray;
    }
    for ($loopi=0;$loopi<$acount;$loopi++){
    $temparray=array($day[$loopi] => $allorate[$loopi]);
    $allonor=$allonor+$temparray;
    }
    //print_r ($allonop);
    for ($loopi=$day_number_arrive;$loopi<$day_number_depart;$loopi++){
    $loopi=sprintf ("%1.0f", $loopi);
    if ($allonop[$loopi]>=$rooms){
    $ok='yes';
    }
    else{
    $ok='no';

    }}
    //echo $days;
    if ($ok=='yes'){
    ?>
    <form action="index.php?content=reg1" method="post">
    <input type="hidden" name="online" value="yes" >
    <input type="hidden" name="location" value="<?echo $location?>" >
    <input type="hidden" name="hotelselect" value="<? echo$r["hotelid"]?>" >
    <input type="hidden" name="rooms" value="<? echo$rooms?>" >
    <input type="hidden" name="arrives" value="<? $newarrive=$arrives[0].$arrives[1]; echo$newarrive?>" >
    <input type="hidden" name="days" value="<? echo$days?>" >
    <input type="hidden" name="alloname" value="<?echo $r["alloname"]?>" >

    <? $result= mysql_db_query($queryab);
    if (mysql_num_rows($result) == 1) {
    echo "We are sorry but the dates you have selected are either being provisionally held or not available. Please select another date range or contact Selina Brady on 01332 680 550 or [email protected]. Thank you.";
    } ?>


    <table summary="" border="0" width=80%>
    <tr>
    <td width="49" rowspan=3 valign=top><?php include('propertySubMenu.php'); ?>&nbsp;</td>

    <td width="76" rowspan=3 valign=top><img src="http://images.cimnet.co.uk/<?echo $r["graphic"];?>" border="0"></td>
    <td width="555" align=right><span class="style5"><b><? echo $r["name"]?>
    <?if ($country=='UNITED KINGDOM'){?>
    <a href="http://www.multimap.com/map/browse.cgi?client=public&db=pc&addr1=&client=public&addr2=&advanced=&addr3=&pc=<?echo $postcode?>&quicksearch=tn33+9eu&cidr_client=none" target=map>Map</a></b>
    <?}?>
    <?if (($country=='FRANCE') or ($country=='France') ){?>
    <a href="http://www.mapquest.fr/cgi-bin/ia_find?link=btwn%2Ftwn-map_results&random=318&event=find_search&uid=u7x6hah508g7x9ha%3A25dutxuaaw&country=Great+Britain&SNV Data=&address=&city=&Zip=<?echo $postcode?>&country=France&Find+Map.x=32&Find+Map.y=11" target=map>Map</a></b>
    <?}?>
    <input type="hidden" name="hotel" value="<? echo $r["name"]?>">
    <?if ($kcflag=='2'){?>
    <br>
    <img src="images/smileysparkle.gif" width="32" height="32">
    <?}?>
    </span></td>
    </tr>
    <tr>

    <td align=right><div align="left" class="style7"><span class="style8"><? echo $r["notes"]?><br>
    <br>
    </span></div></td>
    </tr>
    <tr>
    <td align=right>&nbsp;</td>
    </tr>
    <tr>

    <td align=right colspan=3><span class="style9">

    <?$query2 = "select ratename, rate, notes from venue_rates where hotelid='$hotelid' and (ratename='$company' ) " ;
    $result2= mysql_db_query("$db", $query2);
    while ($r2= mysql_fetch_array($result2)) { ?>
    <?echo $r2["ratename"]?> - <?echo $r2["rate"]?><br>
    <?echo $r2["notes"]?><br>
    <?}?>
    The rate displayed is the property rental charge for the dates you have selected during the seasonal period, exclusive of supplements.
    <select name="rateselect">
    <?
    //$query2 = "select ratename, rate, notes from venue_rates where hotelid='$hotelid' and ratename like '%Southern Sun Resorts%' " ;

    // Sep 7 2006 - [email protected] - fields are referenced by name when the result is used, so it's safe to add another, namely allorate and days
    $query2="select abacus.days,abacus.allorate,abacus.alloname,abacus.rate, venue_main.name from abacus, venue_main where 1 and abacus.year='$year' and abacus.days like '%$dayssql%' and venue_main.hotelid='$hotelid' and abacus.roomtype='$roomtype' and abacus.hotelid=venue_main.hotelid and abacus.alloname like '%$company%'";

    if(!$result2= mysql_db_query("$db", $query2)){echo mysql_error();}
    while ($r2= mysql_fetch_array($result2)) {
    // work out the rate and use that instead of the default
    $t_rate = sum_rates($dayssql, $r2["days"], $r2["allorate"]);
    ?>

    <option value="<?echo $t_rate?>"> &#163;<?echo $t_rate ?> - <?echo $r2["alloname"]?></option>



    <?}?>
    </select>
    <br>
    <br>
    <?echo $terms?><br>
    All rates quoted are in <?echo $rx["currency"];?>

    <input type="hidden" name="terms" value="<?echo $terms?>">
    <br>
    </span></td>
    </tr>
    <tr>

    <td align=right colspan=3><input type="submit" value="Rate Details"></td>
    </tr>


    </table>
    </form>
    <table summary="" border="0" width=500>
    <tr>
    <td><hr></td>
    </tr>
    </table>
    <!-- non allocated ========================================= -->
    <?} } }

    if ($pegabflagx=='2'){

    $querypeg="SELECT
    venue_main.hotelid,
    venue_main.name,
    venue_main.groupname,
    venue_main.website,
    venue_main.graphic,
    venue_main.notes,
    venue_main.country,
    venue_main.kcflag,
    venue_main.terms,
    venue_main.postcode
    from
    venue_main
    WHERE venue_main.hotelid='$hotelidx' ";
    $resultpeg= mysql_db_query("$db", $querypeg);
    while ($r= mysql_fetch_array($resultpeg)) {
    $hotelid=$r["hotelid"];
    $graphic=$r["graphic"];
    $kcflag=$r["kcflag"];
    $terms=$r["terms"];
    $postcode=$r["postcode"];
    $country=$r["country"];
    ?>
    <form action="index.php?content=finish" method="post">
    <input type="hidden" name="location" value="<?echo $location2?>">
    <input type="hidden" name="hotel2" value="<?echo $hotel?>">
    <input type="hidden" name="hotel" value="<? echo $r["name"]?>">
    <input type="hidden" name="arrives" value="<?$arrive=implode ("", $arrives); echo $arrive?>">
    <input type="hidden" name="days" value="<?echo $days?>">
    <input type="hidden" name="rooms" value="<?echo $rooms?>">
    <input type="hidden" name="roomtype" value="<?echo $roomtype?>">

    <input type="hidden" name="rate" value="110.00">
    <table summary="" border="0" width=500>
    <tr>
    <td rowspan=4 valign=top>
    <?if ($graphic!=''){?>
    <img src="http://images.cimnetsolutions.com/<?echo $r["graphic"];?>" border="0">
    <?}
    else{?>
    <img src="http://images.cimnetsolutions.com/nopic.jpg" border="0">
    <?}?>
    </td>
    <td align=right><b><? echo $r["name"]?> <?if ($country=='UNITED KINGDOM'){?>
    <a href="http://www.multimap.com/map/browse.cgi?client=public&db=pc&addr1=&client=public&addr2=&advanced=&addr3=&pc=<?echo $postcode?>&quicksearch=tn33+9eu&cidr_client=none" target=map>Map</a></b><?}?>
    <?if (($country=='FRANCE') or ($country=='France') ){?>
    <a href="http://www.mapquest.fr/cgi-bin/ia_find?link=btwn%2Ftwn-map_results&random=318&event=find_search&uid=u7x6hah508g7x9ha%3A25dutxuaaw&country=Great+Britain&SNV Data=&address=&city=&Zip=<?echo $postcode?>&country=France&Find+Map.x=32&Find+Map.y=11" target=map>Map</a></b><?}?>
    <?if ($kcflag=='2'){?>
    <br><img src="images/smileysparkle.gif" width="32" height="32">
    <?}?>
    </td>
    </tr>
    <tr>

    <td align=right><? echo $r["notes"]?><br><br></td>
    </tr>
    <tr>

    <td align=right><b>
    <?$query2 = "select ratename, rate, notes from venue_rates where hotelid='$hotelid' and (ratename='Corporate rate' or ratename='Rack rate' or ratename='$company') " ;
    $result2= mysql_db_query("$db", $query2);
    while ($r2= mysql_fetch_array($result2)) {
    if ($r2[0]=='Kimberly-Clark'){$rate=$r2[1];}
    ?>
    <?echo $r2["ratename"]?> - <?echo $r2["rate"]?><br>
    <?echo $r2["notes"]?><br>
    <?}?>
    <?echo $terms?><br>
    All rates quoted are in <?echo $rx["currency"];?>
    <input type="hidden" name="rate" value="<?echo $rate?>">
    </b></td>
    </tr>

    <tr>


    <td align=right><input type="submit" value="Rate Details"></td>
    </tr>
    <tr>
    <td colspan=2 align=right><b>please click 'book this hotel' button and your request will be processed and you will be e-mailed with availability</b></td>
    </tr>
    </table></form>
    <table summary="" border="0" width=500>
    <tr>
    <td><hr></td>
    </tr>
    </table>
    <div align="center"><br>
    <?
    } }}?>
    </div>

  • #2
    You really expect someone to sift through all that code and find a bug? Yikes.

    You really should put some effort into narrowing down the problem. Are warning/error messages turned on? Next, trace the path of logic. Use echo statements in strategic places to determine where the logic flows if it's difficult to follow in the code. If you can trace the path of logic and it looks like it should do something other than a blank page, but you just can't see where the problem is, then post the relevant bits of code using the forum's code tags (as described here) and maybe just maybe we'll see something.

    Comment


    • #3
      hmmm I see what you mean

      I tried accessing the top tips for posting but it required username and password - the bit of rogue code I suspect is this:

      $resultab= mysql_db_query("$db", $queryab);
      if (mysql_num_rows($resultab) == 0) {
      echo "We are sorry but the dates you have selected are either being provisionally held or not available. Please select another date range or contact Selina Brady on 01332 680 550 or [email protected][/url]. Thank you.";
      }

      and whats occuring with it is that it displays the echo whether the search return has content or not...

      Comment


      • #4
        Try replacing that deprecated function mysql_db_query() with mysql_query(). And it's always strongly advisable to check the results of the mysql_query() function... always, always, always.

        Comment


        • #5
          Thanks

          I'll give that a go and see what I can break...

          Comment


          • #6
            Well fumigator, still the same result I'm afraid - is there a bit of java which would open up a page if a search return was blan perhaps?

            Comment

            Working...
            X