简体   繁体   English

有关PHP代码的任何想法吗?

[英]Any ideas for a php code for this?

I need to make some math, and I cannot seem to find a way to do it. 我需要做一些数学计算,而我似乎找不到办法。

I have the following table, resulting from this query: 我有以下表,由此查询产生:

SELECT materii.id,
       materii.materie,
        GROUP_CONCAT(note.note) AS note,
        GROUP_CONCAT(DISTINCT teza.`teza`) AS teza


FROM materii
LEFT JOIN teza ON materii.id = teza.id_materie
LEFT JOIN note ON materii.id = note.id_materie
LEFT JOIN elevi ON note.id_elev = elevi.cod_elev 
LEFT JOIN luni ON note.`luna_nota`=luni.`id`
WHERE elevi.`cod_elev` = 1 AND luna_nota = 9
GROUP BY materii.id, materii.materie
ORDER BY materii.materie

表

I need to do something like : 我需要做类似的事情:

$notele = mysql_query($pentrumedie)
                or die("Nu am gasit note in baza de date");
$numar_note = mysql_num_rows($notele);
if($numar_note==0)
{

}
else 
{
    while($rand2=mysql_fetch_array($notele))
    {     
         $note1 = ($rand2['notele'] / $numar_note);
       $medie_septembrie = ($note1 / $cate_note_sunt);
    }
}

I need to do something like that for all the "note", but $rand2['notele'] needs to be the sum of them, if there are more "note", and if there is a value for "teza", then the math formula needs to be: 我需要为所有“注释”做类似的事情,但是$ rand2 ['notele']需要是它们的总和,如果有更多“注意”,并且如果有“teza”的值,那么数学公式需要是:

(($rand2['notele'] / $numar_note) * 3 + teza) / 4

I tried some if functions, but none of them work....Any Ideas? 我尝试了一些功能,但没有一个工作....任何想法? Thanks!!! 谢谢!!!

you can try to change a little bit your sql statement 你可以尝试改变你的sql语句

SELECT materii.id,
   materii.materie,
    SUM(note.note)/COUNT(note.note) AS medie,
    GROUP_CONCAT(DISTINCT teza.`teza`) AS teza
FROM materii
LEFT JOIN teza ON materii.id = teza.id_materie
LEFT JOIN note ON materii.id = note.id_materie
LEFT JOIN elevi ON note.id_elev = elevi.cod_elev 
LEFT JOIN luni ON note.`luna_nota`=luni.`id`
WHERE elevi.`cod_elev` = 1 AND luna_nota = 9
GROUP BY materii.id, materii.materie
ORDER BY materii.materie

And in php use something like 在PHP中使用类似的东西

$medii = array();
while($rand = mysql_fetch_assoc($notele))
{
  if($rand["teza"] == "" || $rand["teza"] == NULL)
  {
   $medii[] = array("materie" => $rand["materie"],
                  "medie" => $rand["medie"]);
  }
  else
  {
   $medii[] = array("materie" => $rand["materie"],
                  "medie" => ((float)$rand["medie"]*3 + (float)$rand["teza"])/4);
   }
}
var_dump($medii);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我试图删除一个使用PHP的mysql文件这里的代码一旦删除按下没有任何发生任何想法? - Im trying to delete a mysql file using php here is the code once delete is pressed nothing happens any ideas? 使用 API 获取数据时,HTML 代码未在 PHP 中解析。 任何想法为什么会发生这种情况? - HTML code not parsing in PHP while using API to fetch data. Any ideas why this is happening? php插入到不向数据库添加数据,有什么想法吗? - php insert into not adding data to database, any ideas? PHP脚本在Dreamweaver中可见,但在浏览器中不可见,有什么想法吗? - php script visible in Dreamweaver but not in browser, any ideas? Slim 框架 - PHP 路由不正确 - 有什么想法吗? - Slim Framework - PHP not routing correctly - any ideas? 关于如何获取PHP表格以返回到特定行/列的任何想法? - Any ideas on how to get PHP form to return to particular row/column? PHP 页面未检测到电流 Session ....有什么想法吗? - PHP Page Not Detecting A Current Session....Any Ideas? 未知文件-wp-config-db.cnf.php-有什么想法吗? - Unknown file - wp-config-db.cnf.php - any ideas? php foreach错误。 任何想法为什么它不能正常工作? - php foreach bug. Any ideas why is it not working properly? 简单的PHP与我们联系表格,用于验证的图像未显示-有任何想法吗? - Simple PHP Contact Us Form, Image For Verification Not Showing - Any Ideas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM