怎么用PHP中的IF和ELSE说“没有结果”

时间:2015-10-21 09:24:20

标签: php joomla

我正在为网站添加一些功能。目前,如果没有结果,“搜索结果”页面只显示一个空白页面。我想给出一条消息。

这是PHP:

    <div class="tag-category">
        <ul class="category list-striped list-unstyled">
        <?php
        $dd=$_REQUEST[ 'destination']; 
        $h=$_REQUEST[ 'hType'];
        $n=$_REQUEST[ 'night'];
        $b=$_REQUEST[ 'beach'];

        if(count($this->data_list )>0)
        { 
           foreach($this->data_list as $d)
           { 
              $data =array(); 
              $data =json_decode($d->images,true); 
              $db = JFactory::getDBO(); 
              $query="SELECT parent_id FROM #__categories where id=".$dd;
              $db->setQuery($query); 
              $dess = $db->loadResult(); 

           if ($dess==11 || $dd==11 )
           { 
                $itemid=137; 
           } 
           else if ($dess==10 || $dd==10 ) 
           { 
               $itemid=144; 
           }
           else if ($dess==12 || $dd==12 ) 
           { 
              $itemid=143; 
           } 
           else if ($dess==15 || $dd==15 ) 
           {
             $itemid=130;
           } 
           else
           { 
             $itemid=112; 
           } 

    $linkk='index.php?option=com_content&view=article&id='.$d->id; 
    $db = JFactory::getDbo(); 
    $query = $db->getQuery(true);
    $query->select($db->quoteName('id')); 
    $query->from($db->quoteName('#__menu')); 
    $query->where($db->quoteName('link') . ' = '. $db->quote($linkk)); $db->setQuery($query);
    $itemid = $db->loadResult(); 
    $link='index.php?option=com_content&view=article&id='.$d->id.'& catid='.$d->catid.'&Itemid='.$itemid

    ?>
         <li class="cat-list-row0 clearfix">
                <h3> 
                 <a href="<?php echo $link; ?>"> <?php echo $d->title; ?> </a>
               </h3>

    <?php

       if($data[ 'image_intro'])
   { ?>
              <img src="<?php echo $data['image_intro']; ?>" alt="">
   <?php } ?>
              <span class="tag-body">
             <p><?php echo $d->introtext; ?> </p> 
             <h4><a href="<?php echo $link; ?>"> READ MORE </a> </h4>
             </span> 
        </li>
   <?php } } ?>
        </ul>
    </div>

我希望我可以在那里放} else { echo "no results" }但是我尝试的任何东西都不起作用。

1 个答案:

答案 0 :(得分:1)

根据你当前的代码,else应该放在最后一个}之后,你可以(并且应该)也缩进你的代码并可能优化它,实际上他非常混乱。

    <div class="tag-category">
    <ul class="category list-striped list-unstyled">
        <?php
$dd = $_REQUEST['destination'];
$h = $_REQUEST['hType'];
$n = $_REQUEST['night'];
$b = $_REQUEST['beach'];

if (count($this->data_list) > 0)
{
foreach($this->data_list as $d)
{
$data = array();
$data = json_decode($d->images, true);
$db = JFactory::getDBO();
$query = "SELECT parent_id FROM #__categories where id=" . $dd;
$db->setQuery($query);
$dess = $db->loadResult();
if ($dess == 11 || $dd == 11)
{
$itemid = 137;
}
  else
if ($dess == 10 || $dd == 10)
{
$itemid = 144;
}
  else
if ($dess == 12 || $dd == 12)
{
$itemid = 143;
}
  else
if ($dess == 15 || $dd == 15)
{
$itemid = 130;
}
  else
{
$itemid = 112;
}

$linkk = 'index.php?option=com_content&view=article&id=' . $d->id;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('id'));
$query->from($db->quoteName('#__menu'));
$query->where($db->quoteName('link') . ' = ' . $db->quote($linkk));
$db->setQuery($query);
$itemid = $db->loadResult();
$link = 'index.php?option=com_content&view=article&id=' . $d->id . '&catid=' . $d->catid . '&Itemid=' . $itemid ?>
        <li class="cat-list-row0 clearfix">
            <h3> <a href="<?php
echo $link; ?>"> <?php
echo $d->title; ?> </a> </h3>
            <?php
if ($data['image_intro'])
{ ?>
            <img src="<?php
echo $data['image_intro']; ?>" alt="">
            <?php
} ?>
            <span class="tag-body">
            <p><?php
echo $d->introtext; ?> </p> 
                <h4><a href="<?php
echo $link; ?>"> READ MORE </a> </h4>
    </span> </li>
        <?php
}
}
  else
{
echo 'Sorry, no results founds'; ?>
    </ul>
}
</div>