显示百分比的结果

时间:2014-12-28 09:38:54

标签: php mysql joomla

您好我的表格中有一个名为百分比的字段,但我想要做的只是显示基于百分比的结果,即如果我设置10它只会显示10%的结果。

这是我的数据库,它是mysql中的Joomla数据库代码

        // Select the required fields from the table.
        $query->select(
            'a.id, a.title, a.simulator, a.generation, a.quality, a.quantity, a.percentage, a.attribute, a.checked_out, a.checked_out_time, a.catid' .
            ', a.state, a.access, a.created, a.created_by, a.version, a.ordering'
        );

        $query->from('#__evolutionary_texture AS a');

        // Join over the users for the checked out user.
        $query->select('uc.name AS editor')
            ->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');

        // Join over the asset groups.
        $query->select('ag.title AS access_level')
            ->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');

        // Join over the species.
        $query->select('category.title AS category_title')
            ->join('LEFT', '#__categories AS category ON category.id = a.catid');

        $query->select('parent.title AS parent_title')
            ->join('left', '#__categories AS parent ON parent.id=category.parent_id');

        // Join over the section.
        //$query->select('section.title AS section_title')
        //  ->join('LEFT', '#__categories AS section ON section.id = a.catid');

        // Join over the users for the author.
        $query->select('ua.name AS author_name')
            ->join('LEFT', '#__users AS ua ON ua.id = a.created_by');

        $query->where('parent.title = ' . $db->quote($species));
        //echo "section = $section";
        $query->where('category.title = ' . $db->quote($section));

        // check where generation.
        $query->where('a.generation = ' . $db->quote($generation));

        // check where simulator.
        $query->where('a.simulator = ' . $db->quote($simulator));

        // Debug the query
        //var_dump($db->replacePrefix( (string) $query ) );

        // Set the query and load the result.
        $db->setQuery($query);

因为我尝试做的只是根据百分比显示纹理,因为这些数据被导入到名为第二人生的游戏中

我的百分比字段现在从0到100

1 个答案:

答案 0 :(得分:0)

在分析您的代码/问题后,我可以建议您关注。

  1. 您需要在SESSION,DATABSE或APPLIATION等级var
  2. 的某处存储变量random_notimes
  3. random_no的值为=array() of 100 int values from 1 to 100 randomly //示例=array(23,15,67,98, ...., 5); // all 1-100 numbers once only
  4. times的值最初为0,每次查询后将增加1。当值达到99时,接下来它将为0并重新计算random_no的值。 //代码在哪里查询数据库
  5. 现在运行条件为a.percentage >= $random_no[$times]
  6. 的查询

    创建 $ randome_no 数组:

     $random_no=array();
     for($i=1;$i<=100;i++){
         $random_no[]=$i;
     }
     shuffle($random_no);
    

    PHP shuffle

    以上方法将随机选择记录percentage