Any ideas for a php code for this?

Acelasi Eu

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

table

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'] / $numar_note) * 3 + teza) / 4

I tried some if functions, but none of them work....Any Ideas? Thanks!!!

beniamin

you can try to change a little bit your sql statement

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

$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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Any ideas to make my code efficient for looping 10 000 000 000 times

Java Code Coverage Ideas?

Any ideas on how i could create a "Object collision detection" with the code i have here? Java, Processing

Any ideas how to install 'ReachabilitySwift' for swift 3?

Segfault in PLT code. Any ideas why?

Static resources in Spring not working. Any ideas?

Why Extended fab does not work? Any Ideas?

Any ideas on how to DRY code this navbar in React?

My code isn't giving the user's the correct feedback. Any ideas how to fix this?

Any ideas to mask the input?

my php adds a blank entry before i even press submit, any ideas?

PHP is there any way to view the generated PHP code

Installed second Google Analytics tracking code, pageviews increased and bounce rate dropped exponentially. Any ideas why?

If statement not running: any ideas?

Get Machine name or any unique code with php

Any Ideas how to optimize my small Jquery Code for a menu?

nginx isn't generating any php-fpm.sock anyone have any ideas why?

cookie not storing, any ideas?

Trying to make a forum using Bootstrap. Code won't work. Any ideas?

Weird PHP Encoding code. Any reason?

Php code to match string if any word is in array

Stripe payments started throwing this error out of nowhere. Any ideas? php laravel framework using stripe API

Having trouble centering layered images, any ideas?

Is there any way to simplify this PHP code?

I want to censor a word to asterisks based on the original length(Happy to *****, dog to *** for example) and my current code doesn't work. Any ideas?

Any ideas on how to make this code efficient?

Any ideas on how to format these lines in vim?

Sending POST request from JS to PHP - $_FILES is NULL, any ideas why?

Any ideas for code reuse between synchronous/asynchronous?

TOP Ranking

HotTag

Archive