Php 显示百分比的结果
您好,我在我的表中有一个名为“百分比”的字段,但我想做的是只显示基于百分比的结果,即如果我设置为10,则在10%的时间内只显示结果 这是我的数据库,它是mysql中的Joomla数据库代码Php 显示百分比的结果,php,mysql,joomla,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.quanti
// 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在分析了您的代码/问题后,我可以建议如下 您需要在会话、数据库或应用级别变量中的某个位置存储一个变量random_no和时间 random_no的值将是=从1到100的100个整数值的数组//example=array23,15,67,98,…,5;//所有1-100号仅限一次 时间值最初为0,每次查询后增加1。当值达到99时,下一个值将为0,并重新计算random\u no的值//在何处查询数据库的代码 现在使用以下条件运行查询:a.percentage>=$random\u no[$times] 创建$randome\u无数组:
上面的方法将随机选择记录百分比时间问题出在哪里?我将根据显示的百分比计算质量,例如常见或罕见等,并显示结果,然后使用数组生成查询结果的数据。我将获得结果列表,然后使用php随机化函数按百分比加权以选择一个。请尝试添加新条件,如我的答案$query->where'a.percentage>='$随机_no[$次];|如果不工作,写下我会尽力解决的问题。
$random_no=array();
for($i=1;$i<=100;i++){
$random_no[]=$i;
}
shuffle($random_no);