-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
That is calling the execute() a second time. If username or email must be unique that could be generating a duplicate key error - check mysql error, don't just assume it's a connection error. Better still, put this line directly before your mysqli_connect() line mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); the all errors will throw a notification without all those if()s
-
Not with your standard of formatting and indenting. It's impossible to spot where one ends and the next one starts and which are nested inside others.
-
Your company hires a firm of expensive marketing consultants who dictate that the main colours in you site's pages should now be pink and lime green. Would you rather alter one css file for the whole site? alter every page in the site individually? resign
-
Within your subject/grade loop you have two sections if($aliran=='S'){ $sql4="SELECT * FROM `qualification_result` where st_aliran='S'"; then else if($aliran=='A'){ $sql4="SELECT * FROM `qualification_result` where st_aliran='S'"; Should they both have where st_aliran='S' or should the second be where st_aliran='A' ?
-
Repeat the total calculation for each array.
-
That doesn't resemble any array I've seen before. If you do echo '<pre>' . print_r( $array , true) . '</pre>'; (where $array is the name of the array you are trying to process - $sub, $s, $y or whatever it is next time you post) then post the output, I can see what you are processing.
-
BTW, have done an rsort(), array_pop() will get you the lowest value.
-
Quicker to use array_slice() $y = [ 0, 4, 10, 8, 8, 10, 0, 14 ]; rsort($y); // descending sort /* check contents $y = Array ( [0] => 14 [1] => 10 [2] => 10 [3] => 8 [4] => 8 [5] => 4 [6] => 0 [7] => 0 ) } */ $top3total = array_sum(array_slice($y, 0, 3)); // get total of first 3 echo $top3total; // 34
-
Interesting. Not only does the code need a rewrite (as I mentioned before) but I can now see the whole database needs rebuilding. Database tables should be normalized, (Google it) not populated with comma-separated lists. If you design the database correctly (so it supports the application), the coding gets a whole lot simpler, removing the need for those dozens of "if" conditions. (there is a tutorial link in my signature, which just happens to be based on students and results, that should give you a guide) [edit...] PS the DB should also eliminate duplicated and conflicting conditions...
-
only this time your array is "$s" and not "$sub".
-
https://invisioncommunity.com/features/content/#forums
-
P.S. I am not sure what you want to do with the query results so I have omitted that. Also not sure what $high_res is supposed to be. Currently it ill always be the same as $res. But if you make use of a couple of arrays, your code reduces to something like this $subjects = [ [ 'MAT', 'M-T', 'FIZ', 'KIM' ], [ 'SNT', 'BIO', 'GRA', 'GKT', 'TEK', 'LKJ', 'PJA', 'PJE', 'PJM', 'PSS', 'PEE', 'MUL', 'PDT', 'RKB', 'RT', 'SS' ], [ 'BM', 'BI', 'SEJ', 'PQS', 'PSI', 'BAT', 'PI' ] ]; $merits = [ 18, 16, 14, 12, 10, 8, 6, 4, 2, 0 ]; foreach(array_combine($subjects, $grades) as $sub => $res){ if (in_array($sub, $subjects[0])) { $main_merit += $merits[$res]; } elseif (in_array($sub, $subjects[1])) { $main_add_merit = $merits[$res]; } elseif (in_array($sub, $subjects[2])) { $main_add_merit1 = $merits[$res]; } $si[] = $main_add_merit1; } rsort($s); for($x = 0; $x < 3; $x++) { echo $s[$x].'<br>'; } $total =$main_merit+$main_add_merit;
-
OK. You can always come back when you have finished throwing your toys out of your pram.
-
When posting code, use the <> button in the toolbar. Do not run queries inside loops. From looking at the code there appear to be 4 main subjects and 16 other ones. The whole code really is in need of a major rewrite. If i knew what was in the $subjects and $grades arrays, and the structure and content of your qualification_result table (and related tables) what the output should look like I could help you with that.
-
You are correct. Are you also saying that the mathematicians from those ancient civilizations also came up with the "PHP modulo operator"? That would be excellent foresight.
-
Adding $a += $sub[$x]; inside the for() loop woud accumulate the sum in $a
-
In what respect is it not correct? I didn't define it. https://www.php.net/manual/en/language.operators.arithmetic.php
-
The modulo operator was invented for situations like this $mytext = "I ❤ PHP"; for ($i=1; $i<=100; $i++) { echo "$i<br>"; if ($i % 5 == 0) echo "$mytext<br>"; }
-
Do you still want to lose 200px on the margins when it's being veiwed on a narrow phone screen? Something to consider.
-
-
A similar approach to mine function ad_litera ($n) { if ($n >3999) return 'NaN'; $n2r = [ 1000 => [ 1 => 'M', 2 => 'MM', 3 => 'MMM' ], 100 => [ 1 => 'C', 2 => 'CC', 3 => 'CCC', 4 => 'CD', 5 => 'D', 6 => 'DC', 7 => 'DCC', 8 => 'DCCC', 9 => 'CM' ], 10 => [ 1 => 'X', 2 => 'XX', 3 => 'XXX', 4 => 'XL', 5 => 'L', 6 => 'LX', 7 => 'LXX', 8 => 'LXXX', 9 => 'XC' ], 1 => [ 1 => 'I', 2 => 'II', 3 => 'III', 4 => 'IV', 5 => 'V', 6 => 'VI', 7 => 'VII', 8 => 'VIII', 9 => 'IX' ], ]; $res = ''; foreach ($n2r as $p => $v) { $x = intdiv($n, $p); $n -= $p*$x; switch ($n) { case 45: $res .= ($n2r[$p][$x] ?? '').'VL'; return $res; break; case 49: $res .= ($n2r[$p][$x] ?? '').'IL'; return $res; break; case 95: $res .= ($n2r[$p][$x] ?? '').'VC'; return $res; break; case 99: $res .= ($n2r[$p][$x] ?? '').'IC'; return $res; break; default: $res .= $n2r[$p][$x] ?? ''; } } return $res; }
-
Attached is a gift for you so you can test all numbers from 1 - 3999 Sample contents... I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX . . MCMVC MCMXCVI MCMXCVII MCMXCVIII MCMIC MM MMI MMII MMIII MMIV MMV . . MMMCMXC MMMCMXCI MMMCMXCII MMMCMXCIII MMMCMXCIV MMMCMVC MMMCMXCVI MMMCMXCVII MMMCMXCVIII MMMCMIC roman_test.txt
-
Because X is not less than the subsequent X, so only the I is subtractive
-