Jump to content

subuntug

Members
  • Content Count

    33
  • Joined

  • Last visited

Community Reputation

0 Neutral

About subuntug

  • Rank
    Newbie

Profile Information

  • Location
    paris
  1. Thank you for your answer, but that's not the solution. Because this query selects just one mark, it selects the best mark for the student amoung all the modules, not the best mark for each module. If there's 10 modules and 15 marks, it should select 10 marks only. Each time there's more thank one mark for a module, it should select the best mark. That's what I need.
  2. Thanks for your answer.But that's not what I need. I'm trying to keep the highest mark for each module not for the entire modules. My table looks like this: +---------+---------+---------------+-------+ | student|module |mark Number |mark | +---------+---------+---------------+-------+ | Mike |Module1 | 1 |15 | +---------+---------+---------------+-------+ |Mike |Module1| 2 |11 +---------+---------+---------------+-------+ | Mike |Module2 | 1 |9 +---------+---------+---------------+-------+ |Mike |Module3 | 1 |10 +---------+---------+---------------+-------+ My question would be, how to select the marks for "Mike" for all the modules, but when a module has more than one mark, ( in my exemple above, the module1 has 2 marks the same student) select only the best mark. I hope my question is now more clear. Thanks in advance for your help.
  3. Hello every body, I have a table which contains exams' marks for student in different modules. Each student can have one or many marks for each module in the table. When I have more than one mark for a student in a module, I have to keep the highest mark. I need to calculate the average for each student in my table. How can I do this with mysql query. I know that there is a query like: SELECT AVG(mark) FROM MyTable WHERE student = 'MyStudent'; But, like I said before, each student may have one or more marks in each module, and in this case, I need to keep the best one for the module where there is more than 1 mark. I tried this query: SELECT AVG(mark) FROM (SELECT MAX(mark) FROM MyTable WHERE student='MyStudent'; But it doesn't seem to work. I got the error message : "#1248 - Every derived table must have its own alias" Thanks in advance for your help.
  4. Thanks boen_robot for your help. Now it's working. But can you tell me where can I add the "WHERE" clause to filter some marks, some modules or some students ?For instance, diplay just marks for the year 2010.Thanks you in advance for your help.
  5. Yes the query failed and mysql tell me : Unknown column 'B211.students' in 'on clause'. Which is true.
  6. Hello; The line 22 correspond to this line :while($row = mysql_fetch_assoc($results)) Here is a copy of my table, if you can test it in your machine.: -- Structure of the table `exam_marks`--CREATE TABLE IF NOT EXISTS `exam_marks` ( `id` int(45) NOT NULL DEFAULT '0', `student` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL COMMENT 'the student\'s id', `mark` float NOT NULL COMMENT 'student \'s mark in the exam', `module` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL COMMENT 'module of the exam') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;---- content of the table `exam_marks`--INSERT INTO `exam_marks` (`id`, `student`, `mark`, `module`) VALUES(3, 'amaiga', 6, 'B211'),(14, 'emerlet', 6, 'B211'),(19, 'ifattel', 6, 'B211'),(23, 'jdvaux', 8.88, 'B211'),(66, 'jGary', 16.5, 'B211'),(42, 'pmitride', 3.33, 'B211'),(67, 'aly', 19, 'C305'),(4, 'amaiga', 4.5, 'C305'),(6, 'cbota', 15, 'C305'),(10, 'cmolina', 3, 'C305'),(15, 'emerlet', 3, 'C305'),(20, 'ifattel', 3, 'C305'),(24, 'jdvaux', 8.88, 'C305'),(70, 'cbota', 16, 'D318'),(13, 'cmolina', 12.22, 'D318'),(17, 'emerlet', 4.5, 'D318'),(75, 'ifattel', 13, 'D318'),(22, 'jdurant', 6, 'D318'),(32, 'lRanni', 8, 'D318'),(33, 'maouinti', 13, 'D318'),(36, 'mKafkar', 19.5, 'D318'),(73, 'aly', 16, 'PP'),(62, 'cbota', 15, 'PP'),(64, 'cmolina', 9, 'PP'),(65, 'jGary', 15.55, 'PP'),(72, 'lRanni', 12, 'PP'); Thanks again.
  7. Hello;thanks for your help (boen_robot) Sure, I tested all the versions of code you proposed, but none works. I always got from mysql. In the last version you proposed, I got this error:Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/subuntug/file-test.php on line 22 Thanks again
  8. Hello,I noticed that early, I had already corrected that, but weirdly, nothing changes. Some marks for some students are missing. For instance, the student with the id ='ifattel' has 3 marks in my table, but only one mark is displayed even when I removed the WHERE clause (student='cbota').Thanks again for your help.
  9. Hello; Both solutions proposed by dsonesuk worked, but not properly. Because I got the HTML table, but not all marks are displayed. I got all the marks for the first student, but only some marks from the other students. This is weird ! I don't understand where is the problem. Why some marks are displayed some are not. I tried this too: $students_marks = mysql_query( "SELECT * FROM v_exam_marks"); $num_marks = mysql_num_rows($students_marks); if($num_marks > 0) { while($r = mysql_fetch_assoc($students_marks)) { $modules[$r['student']][$r['module']] = $r['mark']; } if(is_array($modules)) { echo "<table>\n<tr>\n<th> </th>\n<th>B211</th>\n<th>C305</th>\n<th>D318</th>\n</tr>\n"; foreach($modules as $k => $v) { echo "<tr><td>$k</td>"; echo (isset($modules[$k]['B211'])) ? '<td>' . $modules[$k]['B211'] . '</td>' : '<td> </td>'; echo (isset($modules[$k]['C305'])) ? '<td>' . $modules[$k]['C305'] . '</td>' : '<td> </td>'; echo (isset($modules[$k]['D318'])) ? '<td>' . $modules[$k]['D318'] . '</td>' : '<td> </td>'; echo '</tr>'; } echo '</table>'; } } It's working properly, but the modules are hard-coded and I want to put them in a variable.Thanks again for your help
  10. Hello,Thank you for your answer, but it doesn't work for me. I don't get anything from mysql table. In mysql table I have three columns "student" "module" and "mark". It's a view table which contain marks for students in differents exams (modules). Each student have one or several marks in the table.I don't understand where did come m.students column. Mysql tell me that the column m.students doesn't exist.It's easy to display my table in excel, but very difficult to do so dynamically with php.Thanks
  11. That's what I get when I use the for loop. There's no difference. Here's the content of $myArray:Array( [cbota] => Array ( [0] => Array ( [0] => B211 [1] => 16.5 ) [1] => Array ( [0] => C305 [1] => 16.5 ) ) [cmolina] => Array ( [2] => Array ( [0] => B211 [1] => 6 ) [3] => Array ( [0] => C305 [1] => 3 ) [4] => Array ( [0] => D318 [1] => 12.22 ) ) [ifattel] => Array ( [5] => Array ( [0] => B211 [1] => 6 ) [6] => Array ( [0] => C305 [1] => 3 ) [7] => Array ( [0] => D318 [1] => 6.33 ) ) [jdvaux] => Array ( [8] => Array ( [0] => B211 [1] => 8.88 ) [9] => Array ( [0] => C305 [1] => 8.88 ) [10] => Array ( [0] => D318 [1] => 9 ) ) [jGary] => Array ( [11] => Array ( [0] => D318 [1] => 18 ) ) [lRanni] => Array ( [12] => Array ( [0] => D318 [1] => 8 ) )) But, my main question it's how to turn this array on HTML table like I showed in my first message. Here's an image of the table which I want to fill with marks from my array: Thanks in advance for your help
  12. Hello; I have a Multi-Dimensional Array from mysql table and need to display it as html table. here is the variable holding my array data: $students_marks = mysql_query("SELECT * FROM v_exam_marks); $num_marks = mysql_num_rows($students_marks); for($i=0; $i<$nbr_note; $i++) { $student = mysql_result($students_marks, $i, 'student'); $module = mysql_result($students_marks, $i, 'module'); $mark = mysql_result($students_marks, $i, 'mark'); $myArray[$student][$i] = array($module, $mark); } When I do echo $student. "|". $module. "|". "$mark"."<br />"; I get:cbota|B211|16.5cbota|C305|16.5cmolina|B211|6cmolina|C305|3cmolina|D318|12.22ifattel|B211|6ifattel|C305|3ifattel|D318|6.33jdvaux|B211|8.88jdvaux|C305|8.88jdvaux|D318|9jGary|D318|18lRanni|D318|8What I want it's to display my data in HTML table like this: <table><tr><th> </th><th>B211</th><th>C305</th><th>D318</th></tr><tr><th>cbota</th><td>16.5</td><td>16.5</td><td> </td></tr><tr><th>cmolina</th><td>6</td><td>3</td>12.22<td> </td></tr><tr><th>ifattel</th><td>6</td><td>3</td><td>6.33</td></tr><tr><th>jdvaux</th><td>8.88</td> <td>8.88</td><td>9</td></tr><tr><th>jGary</th><td> </td><td> </td><td>18</td></tr><tr><th>cbota</th><td> </td><td> </td><td>8</td></tr></table> How can I do with php, to get this kind of HTML table from my data base query.Thanks in advances for your help
  13. Thank you so much Synook ! I just got rid of space after the semi colon, and now the problem is solved.Thank you again
  14. That's what I did. I added this line in my environment variable: C:\Program Files\wamp\bin\php\php5.3.1;But it still doesn't work at all ! So, when I type the command echo %path% it shows me this:c:\windows\system32; c:\program files\wamp\bin\php\php5.3.1;So, what's wrong with my path system variable ?Thank you in advance.
  15. Hello;I'm newbie in synfony framwork and PHP development. I use windows cammand line. The problem is: every time I run the command c:/ PHP /somethingthe command line tell me that; PHP is not recognized as internal or external command. So to run PHP I have each time put the full path toward php program in my computer. How can I fix it ?Thank you in advance for your help.
×
×
  • Create New...