2

目前我有一个有两个选择选项的表单,一个可以查看案例 0,一个可以查看案例 4。

我有一个标签,所以我不能使用表单,因为当我选择一个选项时网站会刷新。然后它在两个选项卡中显示该选项。

我试图只有一种选择。但这不起作用。

这是选项卡/表单代码:

<div class="tab1">
<form action="<?php  echo JRoute::_('index.php'); ?>" method="post">
<input type="hidden" name="option" value="com_yoflash" />
<input type="hidden" name="view" value="category" />
<input type="hidden" name="mochicat" value="<?php echo $this->cat->catid; ?>" />
<select name="order" size="1" onchange="submit();">
  <option value="0" <?php if($this->order=="0") echo "selected=\"selected\""; ?>><?php echo JText::_('ORDER_DATE_NEWEST'); ?></option>
  <option value="4" <?php if($this->order=="4") echo "selected=\"selected\""; ?>><?php echo JText::_('ORDER_POPULAR'); ?></option>
</select>
<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
</form>
</div>

我得到了另一个完全相同的 div 标签。在第一个 div 选项卡中,我想查看案例 0 或订单 0。

在第二个 div 选项卡中,我想查看 case4 或 order 4。但我不想让任何表单查看该订单。而不是通过表格选择。

这是开关代码:

$limitstart=JRequest::getInt('limitstart',0);
    if($order==-1) {
      $tmp=$session->get('order');
      if(empty($tmp)) {
        $order=0;
      }
      else {
        $order=$session->get('order');
      }
    }
    $session->set('order',$order);


    $order=$session->get('order');
    $Itemid=JRequest::getInt('Itemid',NULL);

    switch($order){
      case 0:
        $str="ORDER BY date_added DESC";
        break;
      case 1:
        $str="ORDER BY date_added ASC";
        break;
      case 2:
        $str="ORDER BY name ASC";
        break;
      case 3:
        $str="ORDER BY name DESC";
        break;
      case 4:
        $str="ORDER BY stat_clicked DESC";
        break;
      default:
        $str="ORDER BY date_added ASC";
        break;
    }
4

3 回答 3

5

ewww, the switch is a bit ugly, here is a nicer version:

$sortMap = array(
"ORDER BY date_added DESC",
"ORDER BY date_added ASC",
"ORDER BY name ASC",
"ORDER BY name DESC",
"ORDER BY stat_clicked DESC"
);

$str = isset($sortMap[$order]) 
    ? $sortMap[$order]
    : "ORDER BY date_added ASC";

since $order is between 0..4 you might as well exploit the fact that it will map to array indexes and avoid the ugly switch and save yourself a bunch of wasted, cluttered lines in the process.

note: you could also do this with an associative array if $type doesn't conform to normal numeric array indexes, you'd just specify the array index in each element manually like "cat"=>"ORDER BY..." in your sort map array and it should work identically.

于 2012-07-22T13:37:37.563 回答
1

嗯,这就是我想要的。

首先,我正在编辑一个组件。最初它是一个表单,用于查看我想要查看游戏的顺序列表。

但我想要一个标签菜单。一个是新游戏,第二个是流行游戏。

所以我创建了选项卡菜单/系统。然后将代码添加到每个 div 中。因此它们具有相同的代码和形式。但是当我在前。选项卡 1(新游戏)并从选定的列表中选择按日期排序。它查看所有最新的游戏。但是当我拉到另一个选项卡(流行游戏)时,它已更改为查看最新游戏。它就像彼此继承。

这是选项卡的完整代码:

    <div class="tab">
    <h2><a name="newgames" id="newgames">a</a></h2>

<form action="<?php  echo JRoute::_('index.php'); ?>" method="post">
<input type="hidden" name="option" value="com_yoflash" />
<input type="hidden" name="view" value="category" />
<input type="hidden" name="mochicat" value="<?php echo $this->cat->catid; ?>" />
<select name="order" size="1" onchange="submit();">
<option value="0" <?php if($this->order=="0") echo "selected=\"selected\""; ?>><?php echo JText::_('ORDER_DATE_NEWEST'); ?></option>
<option value="4" <?php if($this->order=="4") echo "selected=\"selected\""; ?>><?php echo JText::_('ORDER_POPULAR'); ?></option>
</select>
<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
</form>



 <?php
///////////////////////////////////////
// GAMES BOXES START
///////////////////////////////////////
  $db =& JFactory::getDBO();

  for($i=0;$i<count($this->games);$i++) {
  $game=$this->games[$i];
  $slug=$game->slug;

  $game->imgname=$this->params->get('dir_swf').$slug.'/'.$game->imgname;
  $game->description=$db->getEscaped($game->description);
  $game->description=str_replace("\\\"","\'",$game->description);
  $game->namett=$db->getEscaped($game->name);
  ?>

<div class="game" style="display:block;">

<a style="border:0;" href="<?php echo JRoute::_('index.php/play?option=com_yoflash&view=game&id='.$slug.'&Itemid='.$this->Itemid); ?>" onmouseover="Tip('<strong><?php echo $game->namett; ?></strong><br/> <?php echo $game->description; ?>',WIDTH,300,FADEIN,0,DELAY,0,BGCOLOR, '<?php echo $this->params->get('ttip_bgcolor'); ?>', BORDERCOLOR,'<?php echo $this->params->get('ttip_bordercolor'); ?>',FONTCOLOR,'<?php echo $this->params->get('ttip_fontcolor'); ?>',FONTSIZE,'<?php echo $this->params->get('ttip_fontsize'); ?>',FONTFACE,'<?php echo $this->params->get('ttip_fontface'); ?>')" onmouseout="UnTip()">
<img src="<?php echo $game->imgname; ?>" width="71" height="56" alt="<?php echo $game->name; ?>"/><br/>
<div class="gameName"><?php echo "<p>$game->name</p>"; ?></div>
</a>

<span class="info"><?php echo $game->description; ?></span>

 <span class="gamePlayed"><?php echo "<p>$game->stat_clicked <br/></p>".JText::_("<p> plays</p>") ;?></span> 

 </div>

在这个标签(NEWEST GAMES)中,我只想查看最新的游戏

另一个选项卡(流行游戏)看起来一模一样。

希望描述更多?

于 2012-07-22T14:50:55.573 回答
0

除了我上面的答案之外,我认为您想要的是显示一个 [select] html 下拉列表,您可以在其中“选择”一个排序顺序,这将从数组中提取适当的 SQL 并使用它。所以我建议是这样的

$sortIndex = $_POST["sort"];

$sortMap = array(
"ORDER BY date_added DESC",
"ORDER BY date_added ASC",
"ORDER BY name ASC",
"ORDER BY name DESC",
"ORDER BY stat_clicked DESC"
);
$sortDesc = array(
"Sort by date added in descending order",
"Sort by date added in ascending order",
"Sort by name in ascending order",
"Sort by name in descending order",
"Sort by number of clicks in desending order"
);

$sortType = isset($sortMap[$sortIndex]) 
    ? $sortMap[$sortIndex] 
    : "ORDER BY date_added ASC";

<select name="sort">
    <?php foreach($sortDesc as $k=>$text): ?>
    <option value="<?=$k?>" <?=$sortType==$k?"selected='selected'":""?> ><?=$text?></option>
    <?php endforeach?>
</select>

if you had something similar to this in the page, then you can show the text strings inside the [select] and when one is selected+posted, it'll select the appropriate type from the arrays setup, obviously I haven't tested this在实际页面中,我是即兴创作,但我认为您可以理解我想要做什么?

于 2012-07-22T14:26:25.817 回答