我如何应用 Criteria::LIMIT 上限和下限还是有其他方法?

发布于 2024-12-03 16:57:50 字数 4389 浏览 1 评论 0原文

我在 actions.class.php 的 indexSucces.php 中有此代码,

    //some html for the main page
    <td width='48%' align='right'> 
       <?php include_partial('login', array('form' => $form)) ?>
    </td>

用于索引:

    public function executeIndex()
    {
    $this->form = new RcLoginForm();
    $this->setTemplate('index');
    $this->search_form = new RcSearchForm();
        $this->age_form = new RcAgeTableForm();
    }

    public function executeListmatches(sfWebRequest $request)
    {

    }   

然后是部分 _login.php 代码:

   <form action="<?php echo url_for('password/listmatches' ) ?>"  method="post" >
   <tr>
    <td colspan="2">
        <span class='spn_med_lightblue_rbc'>I am a:</span>  
        <select id="gender1" name="gender1">
            <option value="male1" >Male</option>
            <option value="female1" selected="selected">Female</option>
        </select>  
    </td>
  </tr>
  <tr>
    <td colspan="2">
        <span class='spn_med_lightblue_rbc'>Seeking a:</span>  
        <select id="gender2" name="gender2">
            <option value="male2" >Male</option>
            <option value="female2" selected="selected">Female</option>
        </select>  
    </td>
  </tr>
  <tr>
    <td>
        <span class='spn_med_lightblue_rbc'>Age:</span>  
        <select id="age1" name="age1">
        <?php $ages = RcAgeTablePeer::getById(18); 
            foreach ($ages as $age)
            { 
                //echo $age->getId();
                echo "<option>";
                echo $age->getId();
                echo "</option>";
            }  ?>
        </select>
    </td>
    <td>
        <span class='spn_med_lightblue_rbc'>To:</span>  
        <select id="age2" name="age2">
            <?php foreach ($ages as $age)
            { 
                //echo $age->getId();
                echo "<option>";
                echo $age->getId();
                echo "</option>";
            }  ?>
        </select>  
    </td>
  </tr>
  <tr> 
    <td colspan="2">
        <span class='spn_med_lightblue_rbc'>Location:</span>  
        <select id="province" name="province">
            <option value="all" selected="selected">All</option>
            <option value="ec">Eastern Cape</option>
            <option value="nc">Northern Cape</option>
            <option value="wc">Western Cape</option>
            <option value="fs">Free State</option>
            <option value="gp">Gauteng</option>  
            <option value="kzn">Kzn</option>
            <option value="lim">Limpopo</option>
            <option value="mpu">Mpumulanga</option>  
            <option value="nw">North West</option>  
        </select>  
    </td>  
    <td><input class='submit_img' type="image" src="/images/rainbow/gobuttonbluesmall.png" value="Submit" alt="Submit"></td>
</tr>
<tr></tr>
<tr></tr>
</form>

上面将提供一个主页,其中包含包含网站登录信息的部分(部分 _login)当您点击“执行”按钮时,还会进行快速搜索,表单操作将转到 行动=

这是我的困境..我不属于任何班级,我只是通过 POST 传递选定的值,并使用这些值

在 listmatchesSuccess.php 中

   $matching_rows = RcProfileTablePeer::getAllBySelection($gender_id2,$age1,$age2,$province_id,$from,$limit);

获取我的行,其中在 RcProfileTablePeer.php 中:

 static public function getAllBySelection($gender2,$age1,$age2,$province_id,$from,$limit)
{
    $criteria = new Criteria();
    $criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
    $criteria->add(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);
    $criteria->add(RcProfileTablePeer::GENDER_ID,$gender2, Criteria::EQUAL);
    if ($province_id <> 10)
        $criteria->addAnd(RcProfileTablePeer::PROVINCE_ID,$province_id, Criteria::EQUAL);
    $criteria->setLimit($limit);
    return self::doSelect($criteria);
}

希望这一切现在更有意义:) 谢谢

i have this code in indexSucces.php

    //some html for the main page
    <td width='48%' align='right'> 
       <?php include_partial('login', array('form' => $form)) ?>
    </td>

in the actions.class.php for index i have:

    public function executeIndex()
    {
    $this->form = new RcLoginForm();
    $this->setTemplate('index');
    $this->search_form = new RcSearchForm();
        $this->age_form = new RcAgeTableForm();
    }

    public function executeListmatches(sfWebRequest $request)
    {

    }   

then the partial _login.php code:

   <form action="<?php echo url_for('password/listmatches' ) ?>"  method="post" >
   <tr>
    <td colspan="2">
        <span class='spn_med_lightblue_rbc'>I am a:</span>  
        <select id="gender1" name="gender1">
            <option value="male1" >Male</option>
            <option value="female1" selected="selected">Female</option>
        </select>  
    </td>
  </tr>
  <tr>
    <td colspan="2">
        <span class='spn_med_lightblue_rbc'>Seeking a:</span>  
        <select id="gender2" name="gender2">
            <option value="male2" >Male</option>
            <option value="female2" selected="selected">Female</option>
        </select>  
    </td>
  </tr>
  <tr>
    <td>
        <span class='spn_med_lightblue_rbc'>Age:</span>  
        <select id="age1" name="age1">
        <?php $ages = RcAgeTablePeer::getById(18); 
            foreach ($ages as $age)
            { 
                //echo $age->getId();
                echo "<option>";
                echo $age->getId();
                echo "</option>";
            }  ?>
        </select>
    </td>
    <td>
        <span class='spn_med_lightblue_rbc'>To:</span>  
        <select id="age2" name="age2">
            <?php foreach ($ages as $age)
            { 
                //echo $age->getId();
                echo "<option>";
                echo $age->getId();
                echo "</option>";
            }  ?>
        </select>  
    </td>
  </tr>
  <tr> 
    <td colspan="2">
        <span class='spn_med_lightblue_rbc'>Location:</span>  
        <select id="province" name="province">
            <option value="all" selected="selected">All</option>
            <option value="ec">Eastern Cape</option>
            <option value="nc">Northern Cape</option>
            <option value="wc">Western Cape</option>
            <option value="fs">Free State</option>
            <option value="gp">Gauteng</option>  
            <option value="kzn">Kzn</option>
            <option value="lim">Limpopo</option>
            <option value="mpu">Mpumulanga</option>  
            <option value="nw">North West</option>  
        </select>  
    </td>  
    <td><input class='submit_img' type="image" src="/images/rainbow/gobuttonbluesmall.png" value="Submit" alt="Submit"></td>
</tr>
<tr></tr>
<tr></tr>
</form>

the above will give a home page with a section(the partial _login) that contains the login to the website and also a quick search when you hit the go button the form action will go to
action="

this is my dilemma..i am not in any class, i just pass on the selected values through POST and use those values to get my rows

in listmatchesSuccess.php

   $matching_rows = RcProfileTablePeer::getAllBySelection($gender_id2,$age1,$age2,$province_id,$from,$limit);

where above in RcProfileTablePeer.php:

 static public function getAllBySelection($gender2,$age1,$age2,$province_id,$from,$limit)
{
    $criteria = new Criteria();
    $criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
    $criteria->add(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);
    $criteria->add(RcProfileTablePeer::GENDER_ID,$gender2, Criteria::EQUAL);
    if ($province_id <> 10)
        $criteria->addAnd(RcProfileTablePeer::PROVINCE_ID,$province_id, Criteria::EQUAL);
    $criteria->setLimit($limit);
    return self::doSelect($criteria);
}

hope all this makes better sense now :)
thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的奇迹 2024-12-10 16:57:50

我希望我明白你在问什么,

我想为你的查询添加一个限制

$criteria->setLimit(10);

,如果你想在 symfony 中创建一个寻呼机,我建议使用 propel pager 类
例如
$this->page = $request->getParameter('page', 1);
$c = 新标准();

$c->add(UserPeer::Status_ID,1);

$this->pager = new sfPropelPager('User', $limit);
$this->pager->setCriteria($c));
$this->pager->setPeerMethod('doSelect');
$this->pager->setPage($this->page);
$this->pager->init(); 

您可以参考此链接 http://www.symfony-project.org/cookbook/ 1_0/en/pager 了解更多信息。

我希望这能回答你的问题;

I hope I understand what you are asking,

I you want to add a limit to your query

$criteria->setLimit(10);

and also if you want to create a pager in symfony, I would suggest the propel pager class
e.g.
$this->page = $request->getParameter('page', 1);
$c = new Criteria();

$c->add(UserPeer::Status_ID,1);

$this->pager = new sfPropelPager('User', $limit);
$this->pager->setCriteria($c));
$this->pager->setPeerMethod('doSelect');
$this->pager->setPage($this->page);
$this->pager->init(); 

You can reference this link http://www.symfony-project.org/cookbook/1_0/en/pager for more information .

I hope that answers your question;

妳是的陽光 2024-12-10 16:57:50

您的查询中存在错误:

$criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
$criteria->add(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);

结果查询rc_profile.age >= :age1

如果您正在查找年龄在 $age1 和 $age2 之间的对象,这应该可以解决问题:

$criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
$criteria->addAnd(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);

结果查询rc_profile.age >= :age1 AND rc_profile.age <= :age2

请注意,您应该使用 $criteria->addAnd$criteria->addOr 来组合相同的条件 柱子。

There is an error in your query:

$criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
$criteria->add(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);

Resulting query: rc_profile.age >= :age1.

If you are looking for the objects with age between $age1 and $age2, this should do the trick:

$criteria->add(RcProfileTablePeer::AGE,$age1,Criteria::GREATER_EQUAL);
$criteria->addAnd(RcProfileTablePeer::AGE,$age2,Criteria::LESS_EQUAL);

Resulting query: rc_profile.age >= :age1 AND rc_profile.age <= :age2

Note that you should use $criteria->addAnd or $criteria->addOr to combine the conditions FOR THE SAME COLUMN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文