CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

Author: bender

tumpang tanye psl html n php

[Copy link]
Post time 1-3-2009 11:59 AM | Show all posts

Reply #140 BorderManager's post

Thanks boardmanager.. kau memang power lah..
Aku gunakan contoh yang kau bagi sebagai panduan untuk db aku yang complicated sikit dari yang kat atas dan bila aku test menjadik keluar ouput sebagaimana yang di plan..

tapi nak tanya sikit:

1. Width cell tak leh nak adjust ke? AKu try tambah <TD width="100"> kat mana mana yang berkenaan langsung tak ada effect.

[ Last edited by  sadiq_segaraga at 1-3-2009 12:58 PM ]
Reply

Use magic Report


ADVERTISEMENT


Post time 1-3-2009 01:49 PM | Show all posts
ni utk kurangkan jumlah query
  1. $conn    = mysql_connect($host, $user, $passwd) or die(mysql_error());
  2. $link    = mysql_select_db($db, $conn) or die(mysql_error());

  3. //cari senarai subject dlm database
  4. $sql = "SELECT subject FROM student GROUP BY subject";
  5. $query = mysql_query($sql);
  6. while($row=mysql_fetch_assoc($query)){
  7. $subject[] = $row['subject'];
  8. }

  9. //listkan student name
  10. $sql = "SELECT name FROM student GROUP BY name";
  11. $query = mysql_query($sql);
  12. ?>
  13. <table border="1">
  14. <tr>
  15. <td rowspan="2" width="200">Name</td>
  16. <!-- display subject name -->
  17. <? for($i=0;$i<count($subject);$i++){ ?>
  18. <td colspan="3" align="center"><?= $subject[$i] ?></td>
  19. <? } ?>
  20. </tr>
  21. <!-- display other fields -->
  22.   <? for($i=0;$i<count($subject);$i++){ ?>
  23.   <td width="100" align="center">Mark</td>
  24.   <td width="100" align="center">Grade</td>
  25.   <td width="100" align="center">Attandance</td>
  26. <? } ?>
  27. <? while($row=mysql_fetch_assoc($query)){ ?>
  28. <tr align="center">
  29. <!-- display name -->
  30. <td align="left"><?= $row['name'] ?></td>
  31. <?
  32. //listtkan semua data student dlm array
  33. $student=array();
  34. $sql2="SELECT * FROM student WHERE name = '".$row['name']."'";
  35. $query2 = mysql_query($sql2);
  36. while($row2=mysql_fetch_assoc($query2)){
  37. $student[$row2['subject']]=$row2;
  38. }
  39. //cari maklumat mengikut subject
  40. for($j=0;$j<count($subject);$j++){
  41. if($student[$subject[$j]]['subject']){
  42. //jika ada display data
  43. echo '<td>'.$student[$subject[$j]]['mark'].'</td><td>'.$student[$subject[$j]]['grade'].'</td><td>'.$student[$subject[$j]]['attandance'].'</td>';
  44. }else{
  45. //jika takde displau empty cell
  46. echo '<td> </td><td> </td><td> </td>';
  47. }}
  48. ?>
  49. </tr>
  50. <? } ?>
  51. </table>
Copy the Code
Reply

Use magic Report

Post time 1-3-2009 06:35 PM | Show all posts
Originally posted by BorderManager at 1-3-2009 10:20 AM
ko kena buat macam n

$sql = "SELECT COUNT(sesi) FROM rekodindividu AS total WHERE nokp = '$nokp' ";
$result = mysql_query($sql) or die("SQL select statement failed";);
if($row = mysql_fetch_ ...



tq...dah bolehh
Reply

Use magic Report

Post time 2-3-2009 12:10 AM | Show all posts
boardmanager...cane nak cr source code cani ek...ader cadangan takk

Reply

Use magic Report

Post time 2-3-2009 01:18 AM | Show all posts
guna javascript je
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
  5. <title>Untitled Document</title>
  6. <script type="text/javascript">
  7. function collapseAll(){
  8. var menuDiv = document.getElementById("menu");
  9. var divs = menuDiv.getElementsByTagName("div");
  10. var div;
  11. for (i = 0; i < divs.length; i++){
  12. div = divs[i];
  13. div.style.display = "none";
  14. }}
  15. function displayRow(Id){
  16. var row = document.getElementById("sub"+Id);
  17. if (row.style.display == '') row.style.display = 'none';
  18. else row.style.display = '';
  19. }
  20. </script>
  21. </head>
  22. <body onload="collapseAll();">
  23. <table width="200" border="1" id="menu">
  24.   <tr>
  25.     <td><a href="#" id="menu1" onclick="displayRow('menu1');">menu1</a>
  26.     <div id="submenu1">
  27.     <p>submenu1.1</p>
  28.     <p>submenu1.2</p>
  29.     <p>submenu1.3</p>
  30.     </div>
  31.     </td>
  32.   </tr>
  33.   <tr>
  34.     <td><a href="#" id="menu2" onclick="displayRow('menu2');">menu2</a>
  35.     <div id="submenu2">
  36.     <p>submenu2.1</p>
  37.     <p>submenu2.2</p>
  38.     <p>submenu2.3</p>
  39.     </div>
  40.     </td>
  41.   </tr>
  42. </table>
  43. </body>
  44. </html>
Copy the Code
Reply

Use magic Report

Post time 2-3-2009 08:38 PM | Show all posts
Boardmanager

Kalau kita ada table cam kat bawah ni:


Nama                                 Markah

Abu                                  55
Kassim                               54
Sulaiman Akhlaken               36
Hussein Lempoyang             78
Abdul Wahub                      66
Abdul Wahab                      35
Kassim Masdor                      44
...
...

Camna nak kira sum of 4 highest mark plus 10% of the 5th highest mark?
Reply

Use magic Report

Follow Us
Post time 2-3-2009 09:21 PM | Show all posts
macam n ka???
  1. $sql = "SELECT mark FROM student ORDER BY mark desc LIMIT 5";
  2. $query = mysql_query($sql);
  3. while($row=mysql_fetch_assoc($query)){
  4. $i++;
  5. $mark+=$i<5?$row['mark']:$row['mark']*0.10;
  6. }
  7. echo $mark;
Copy the Code
Reply

Use magic Report

Post time 3-3-2009 02:14 PM | Show all posts

Reply #147 BorderManager's post

Thanks boardmanager...

Aku ingat nak amik code yang kau bagi tu adjust kat aku punya code (note: sebenarnya code ko jugak) supaya aku dapat buat report seperti dibawah:

NamaPhysicChemistryBiologyEnglishEconomicsAccountingBest of 4 Subjects +10% (of 5th)
Kassim Patalon508535968175x
Kassim Baba525266857273x
Sadiq Segaraga689685737362x
Abdul Wahab777584658568x
Abdul Wahub544272814492x

Yang part Nama and markah subject tu, dah settel dah (Note: dengan pertolongan kau), cuma aku dah test 3 jam aku mainkan coding tu, adjust sana adjust sini tak dapat part yang Best of 4 Subjects + 10% (of 5th) tu.

Camna ya? Thanks for your help. Kalau kau duk JB, for sure aku belanja ko makan.


Reply

Use magic Report


ADVERTISEMENT


Post time 3-3-2009 03:07 PM | Show all posts
aik mcm mana tau aku tak dok JB???
sian ko sampai 3 jam... isss iss
kalau nk belanja call je no ni 1300-13-1300

  1. //cari senarai subject dlm database
  2. $sql = "SELECT subject FROM student GROUP BY subject";
  3. $query = mysql_query($sql);
  4. while($row=mysql_fetch_assoc($query)){
  5. $subject[] = $row['subject'];
  6. }
  7. //listkan student name
  8. $sql = "SELECT name FROM student GROUP BY name";
  9. $query = mysql_query($sql);
  10. ?>
  11. <table border="1">
  12. <tr align="center">
  13. <td rowspan="2" width="200" align="left">Name</td>
  14. <!-- display subject name -->
  15. <? for($i=0;$i<count($subject);$i++){ ?>
  16. <td colspan="3"><?= $subject[$i] ?></td>
  17. <? } ?>
  18. <td rowspan="2" width="200">Best of 4 Subjects +10% (of 5th)</td>
  19. </tr>
  20. <!-- display other fields -->
  21.   <? for($i=0;$i<count($subject);$i++){ ?>
  22.   <td width="60" align="center">Mark</td>
  23.   <td width="60" align="center">Grade</td>
  24.   <td width="60" align="center">Attandance</td>
  25. <? } ?>
  26. <? while($row=mysql_fetch_assoc($query)){ ?>
  27. <tr align="center">
  28. <!-- display name -->
  29. <td align="left"><?= $row['name'] ?></td>
  30. <?
  31. //listtkan semua data student dlm array
  32. $i=0;
  33. $mark=0;
  34. $student=array();
  35. $sql2="SELECT * FROM student WHERE name = '".$row['name']."' ORDER BY mark DESC";
  36. $query2 = mysql_query($sql2);
  37. while($row2=mysql_fetch_assoc($query2)){
  38. $student[$row2['subject']]=$row2;
  39. $i++;
  40. if($i<5){
  41. $mark+=$row2['mark'].' ';
  42. }elseif($i==5){
  43. $mark+=$row2['mark']*0.10;
  44. }}
  45. //cari maklumat mengikut subject
  46. for($j=0;$j<count($subject);$j++){
  47. if($student[$subject[$j]]['subject']){
  48. //jika ada display data
  49. echo '<td>'.$student[$subject[$j]]['mark'].'</td><td>'.$student[$subject[$j]]['grade'].'</td><td>'.$student[$subject[$j]]['attandance'].'</td>';
  50. }else{
  51. //jika takde displau empty cell
  52. echo '<td> </td><td> </td><td> </td>';
  53. }}
  54. ?>
  55. <td><?= $mark ?></td>
  56. </tr>
  57. <? } ?>
  58. </table>
Copy the Code
Reply

Use magic Report

Post time 4-3-2009 12:06 AM | Show all posts
TQ boardmanager ..
nanti dah setel projek ni aku kasi call delivery Piza suruh diorang hantar Piza kat tempat ko
Lu memang best ler. Tak pernah aku jumpa orang yang sanggup kongsi ilmu macam kau dalam arena forum ni..
Ni ada problem lagi.. ada tambahan sikit kat bawah tu.. aku dah cuba sedaya upaya aku sampai tertido aku depan laptop aku ni..

NamaPhysicChemistryBiologyEnglishEconomicsAccountingBest of 4 Subjects +10% (of 5th)
Kassim Patalon498535
81
x
Kassim Baba525266
7273x
Sadiq Segaraga68
85737362x
Abdul Wahab
758465
68x
Abdul Wahub544272814492x
Number of students445344
Number of pass335334
% of passes757510010075100

Pass rate : >50
Reply

Use magic Report

Post time 4-3-2009 12:33 AM | Show all posts
boardmanager...........nak tanyer la....kalo dlm database kite simpan markah.............n then bile kite nak paparkan...cane kite nak setkan gred...so krienye dlm DB ade markah je..bile kite papar baru kite nak setkan gred dier..pakai if else kan...tp cane ek..
Reply

Use magic Report

Post time 4-3-2009 02:15 AM | Show all posts
peh... mencabar betul request ko....aku try gak
  1. $conn    = mysql_connect($host, $user, $passwd) or die(mysql_error());
  2. $link    = mysql_select_db($db, $conn) or die(mysql_error());
  3. $pass_mark = 50;

  4. function grade($mark){
  5.     global $pass_mark;
  6.     if(is_numeric($mark)){
  7.         switch($mark):
  8.         case $mark>=90:
  9.         $grade='A';
  10.         break;
  11.         case $mark>=80&&$mark<90:
  12.         $grade='B';
  13.         break;
  14.         case $mark>=70&&$mark<80:
  15.         $grade='C';
  16.         break;
  17.         case $mark>=60&&$mark<70:
  18.         $grade='D';
  19.         break;
  20.         case $mark>=50&&$mark<60:
  21.         $grade='E';
  22.         break;
  23.         case $mark<$pass_mark:
  24.         $grade='F';
  25.         break;
  26.     endswitch;
  27.     return $grade;
  28.     }
  29. }

  30. $sql = "SELECT subject FROM student GROUP BY subject";
  31. $query = mysql_query($sql);
  32. while($row=mysql_fetch_assoc($query)){
  33.     $subject[] = $row['subject'];
  34. }

  35. $sql = "SELECT subject, SUM(IF(mark is not null,1,0)) AS nos, SUM(IF(mark is not null,1,0) AND IF(mark >=".$pass_mark.",1,0)) AS nop FROM student s GROUP BY subject";
  36. $query = mysql_query($sql);
  37. while($row=mysql_fetch_assoc($query)){
  38.     $nos[$row['subject']] = $row;
  39. }

  40. $sql = "SELECT name FROM student GROUP BY name";
  41. $query = mysql_query($sql);
  42. ?>
  43. <table border="1">
  44. <tr>
  45. <td width="200">Name</td>
  46. <? for($i=0;$i<count($subject);$i++){ ?>
  47. <td colspan="2" align="center"><?= $subject[$i] ?></td>
  48. <? } ?>
  49. <td width="200">Best of 4 Subjects +10% (of 5th)</td>
  50. </tr>
  51. <? while($row=mysql_fetch_assoc($query)){ ?>
  52. <tr align="center">
  53. <td align="left"><?= $row['name'] ?></td>
  54. <?
  55. $i=0;
  56. $top5=0;
  57. $student=array();
  58. $sql2="SELECT * FROM student WHERE name = '".$row['name']."'";
  59. $query2 = mysql_query($sql2);
  60. while($row2=mysql_fetch_assoc($query2)){
  61.     $student[$row2['subject']]=$row2;
  62.     $i++;
  63.     if($i<5)
  64.         $top5+=$row2['mark'].' ';
  65.     elseif($i==5)
  66.         $top5+=$row2['mark']*0.10;
  67. }

  68. for($j=0;$j<count($subject);$j++){
  69.     if($student[$subject[$j]]['subject']){
  70.         $mark = $student[$subject[$j]]['mark'];
  71.         if(!$mark)
  72.             $td = '<td colspan="2"> </td>';
  73.         elseif(grade($mark)=='F')
  74.             $td = '<td style="color:#FF0000">'.$mark.'</td><td style="color:#FF0000">'.grade($mark).'</td>';
  75.         else
  76.             $td = '<td>'.$mark.'</td><td>'.grade($mark).'</td>';
  77.     }else{
  78.         $td = '<td colspan="2"> </td>';
  79.     }
  80.     $nos[$j]=$ns;
  81.     echo $td;
  82. }

  83. ?>
  84. <td><?= number_format($top5,1) ?></td>
  85. </tr>
  86. <? } ?>
  87. <tr align="center">
  88.   <td align="left">No of Student </td>
  89.   <? for($s=0;$s<count($subject);$s++){ ?>
  90.   <td colspan="2"><?= $nos[$subject[$s]]['nos'] ?></td>
  91.   <? } ?>
  92.   <td> </td>
  93. </tr>
  94. <tr align="center">
  95.   <td align="left">No of Pass </td>
  96.   <? for($s=0;$s<count($subject);$s++){ ?>
  97.   <td colspan="2"><?= $nos[$subject[$s]]['nop'] ?></td>
  98.   <? } ?>
  99.   <td> </td>
  100. </tr>
  101. <tr align="center">
  102.   <td align="left">% of passes</td>
  103.   <? for($s=0;$s<count($subject);$s++){ ?>
  104.   <td colspan="2"><?= number_format($nos[$subject[$s]]['nop']/$nos[$subject[$s]]['nos']*100,2) ?>%</td>
  105.   <? } ?>
  106.   <td> </td>
  107. </tr>
  108. </table>
Copy the Code


**tak rugi kedekut ilmu
Reply

Use magic Report

Post time 4-3-2009 02:17 AM | Show all posts
Originally posted by pzan213 at 4-3-2009 12:33 AM
boardmanager...........nak tanyer la....kalo dlm database kite simpan markah.............n then bile kite nak paparkan...cane kite nak setkan gred...so krienye dlm DB ade markah je..bile kite pap ...


tengok posting aku atas n......

guna function -> switch

database utk script di atas
  1. CREATE TABLE  `test`.`student` (
  2.   `student_id` int(5) NOT NULL auto_increment,
  3.   `name` varchar(20) default NULL,
  4.   `subject` varchar(20) default NULL,
  5.   `mark` int(4) default NULL,
  6.   `grade` varchar(4) default NULL,
  7.   `attandance` int(4) default NULL,
  8.   PRIMARY KEY  (`student_id`)
  9. ) ENGINE=MyISAM AUTO_INCREMENT=39 DEFAULT CHARSET=latin1;

  10. --
  11. -- Dumping data for table `test`.`student`
  12. --

  13. INSERT INTO `test`.`student` VALUES  (9,'Kassim Patalon','Physic',49,NULL,NULL),
  14. (10,'Kassim Baba','Physic',52,NULL,NULL),
  15. (11,'Sadiq Segaraga','Physic',68,NULL,NULL),
  16. (12,'Abdul Wahab','Physic',NULL,NULL,NULL),
  17. (13,'Abdul Wahub','Physic',54,NULL,NULL),
  18. (14,'Kassim Patalon','Chemistry',85,NULL,NULL),
  19. (15,'Kassim Baba','Chemistry',52,NULL,NULL),
  20. (16,'Sadiq Segaraga','Chemistry',NULL,NULL,NULL),
  21. (17,'Abdul Wahab','Chemistry',75,NULL,NULL),
  22. (18,'Abdul Wahub','Chemistry',42,NULL,NULL),
  23. (19,'Kassim Patalon','Biology',35,NULL,NULL),
  24. (20,'Kassim Baba','Biology',66,NULL,NULL),
  25. (21,'Sadiq Segaraga','Biology',85,NULL,NULL),
  26. (22,'Abdul Wahab','Biology',84,NULL,NULL),
  27. (23,'Abdul Wahub','Biology',72,NULL,NULL),
  28. (24,'Kassim Patalon','English',NULL,NULL,NULL),
  29. (25,'Kassim Baba','English',NULL,NULL,NULL),
  30. (26,'Sadiq Segaraga','English',73,NULL,NULL),
  31. (27,'Abdul Wahab','English',65,NULL,NULL),
  32. (28,'Abdul Wahub','English',81,NULL,NULL),
  33. (29,'Kassim Patalon','Economics',81,NULL,NULL),
  34. (30,'Kassim Baba','Economics',72,NULL,NULL);
  35. INSERT INTO `test`.`student` VALUES  (31,'Sadiq Segaraga','Economics',73,NULL,NULL),
  36. (32,'Abdul Wahab','Economics',NULL,NULL,NULL),
  37. (33,'Abdul Wahub','Economics',44,NULL,NULL),
  38. (34,'Kassim Patalon','Accounting',NULL,NULL,NULL),
  39. (35,'Kassim Baba','Accounting',73,NULL,NULL),
  40. (36,'Sadiq Segaraga','Accounting',62,NULL,NULL),
  41. (37,'Abdul Wahab','Accounting',68,NULL,NULL),
  42. (38,'Abdul Wahub','Accounting',92,NULL,NULL);
Copy the Code

[ Last edited by  BorderManager at 4-3-2009 02:25 AM ]
Reply

Use magic Report

Post time 4-3-2009 01:30 PM | Show all posts
board...cane nak buang yg table last nie...?

Reply

Use magic Report

Post time 4-3-2009 01:48 PM | Show all posts
lorrr delete je la...

  1. <table border="1">
  2. <tr>
  3. <td width="200">Name</td>
  4. <? for($i=0;$i<count($subject);$i++){ ?>
  5. <td colspan="2" align="center"><?= $subject[$i] ?></td>
  6. <? } ?>
  7. </tr>
  8. <? while($row=mysql_fetch_assoc($query)){ ?>
  9. <tr align="center">
  10. <td align="left"><?= $row['name'] ?></td>
  11. <?
  12. $i=0;
  13. $top5=0;
  14. $student=array();
  15. $sql2="SELECT * FROM student WHERE name = '".$row['name']."'";
  16. $query2 = mysql_query($sql2);
  17. while($row2=mysql_fetch_assoc($query2)){
  18.     $student[$row2['subject']]=$row2;
  19. }

  20. for($j=0;$j<count($subject);$j++){
  21.     if($student[$subject[$j]]['subject']){
  22.         $mark = $student[$subject[$j]]['mark'];
  23.         if(!$mark)
  24.             $td = '<td colspan="2"> </td>';
  25.         elseif(grade($mark)=='F')
  26.             $td = '<td style="color:#FF0000">'.$mark.'</td><td style="color:#FF0000">'.grade($mark).'</td>';
  27.         else
  28.             $td = '<td>'.$mark.'</td><td>'.grade($mark).'</td>';
  29.     }else{
  30.         $td = '<td colspan="2"> </td>';
  31.     }
  32.     $nos[$j]=$ns;
  33.     echo $td;
  34. }

  35. ?>
  36. </tr>
  37. <? } ?>
  38. <tr align="center">
  39.   <td align="left">No of Student </td>
  40.   <? for($s=0;$s<count($subject);$s++){ ?>
  41.   <td colspan="2"><?= $nos[$subject[$s]]['nos'] ?></td>
  42.   <? } ?>
  43. </tr>
  44. <tr align="center">
  45.   <td align="left">No of Pass </td>
  46.   <? for($s=0;$s<count($subject);$s++){ ?>
  47.   <td colspan="2"><?= $nos[$subject[$s]]['nop'] ?></td>
  48.   <? } ?>
  49. </tr>
  50. <tr align="center">
  51.   <td align="left">% of passes</td>
  52.   <? for($s=0;$s<count($subject);$s++){ ?>
  53.   <td colspan="2"><?= number_format($nos[$subject[$s]]['nop']/$nos[$subject[$s]]['nos']*100,2) ?>%</td>
  54.   <? } ?>
  55. </tr>
  56. </table>
Copy the Code
Reply

Use magic Report

Post time 4-3-2009 02:33 PM | Show all posts
konpius nak delete mane 1...hihihih
Reply

Use magic Report


ADVERTISEMENT


Post time 4-3-2009 04:25 PM | Show all posts
aik.. torai je la delete.. salah undo balik

**tip
kalau nk buat report mcm kat atas tu mula2 jangan guna table dulu, guna je space atau tanda | [] ,

table n boleh peningkan kepala
Reply

Use magic Report

Post time 4-3-2009 06:06 PM | Show all posts
Mr Boardmanager

Camna kalau kena nak disablekan warning warning yang keluar dalam result kita? contohnya warning seperti dibawah ni:

Warning: Division by zero in C:\xampp\htdocs\erms\report-mufy-intake.php on line 160
0.00%

Kasi report tak cantik aja warning-warning ni...
Reply

Use magic Report

Post time 5-3-2009 08:42 AM | Show all posts
Originally posted by sadiq_segaraga at 4-3-2009 18:06
Mr Boardmanager

Camna kalau kena nak disablekan warning warning yang keluar dalam result kita? contohnya warning seperti dibawah ni:

Warning: Division by zero in C:\xampp\htdocs\erms\report ...


ko set ni kat top script ko

error_reporting(E_ERROR);

or

dekat function ko yg trigger error (line 160) tu ko letak jer menda ni '@'

cth

@$jumlah=$subJumlah/0;

[ Last edited by  slier81 at 5-3-2009 10:19 ]
Reply

Use magic Report

Post time 5-3-2009 09:27 AM | Show all posts
baru nak jawap...dah ada org tolong jawap...thank you
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

10-1-2025 01:33 PM GMT+8 , Processed in 0.394455 second(s), 28 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list