|
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 ] |
|
|
|
|
|
|
|
ni utk kurangkan jumlah query
- $conn = mysql_connect($host, $user, $passwd) or die(mysql_error());
- $link = mysql_select_db($db, $conn) or die(mysql_error());
- //cari senarai subject dlm database
- $sql = "SELECT subject FROM student GROUP BY subject";
- $query = mysql_query($sql);
- while($row=mysql_fetch_assoc($query)){
- $subject[] = $row['subject'];
- }
- //listkan student name
- $sql = "SELECT name FROM student GROUP BY name";
- $query = mysql_query($sql);
- ?>
- <table border="1">
- <tr>
- <td rowspan="2" width="200">Name</td>
- <!-- display subject name -->
- <? for($i=0;$i<count($subject);$i++){ ?>
- <td colspan="3" align="center"><?= $subject[$i] ?></td>
- <? } ?>
- </tr>
- <!-- display other fields -->
- <? for($i=0;$i<count($subject);$i++){ ?>
- <td width="100" align="center">Mark</td>
- <td width="100" align="center">Grade</td>
- <td width="100" align="center">Attandance</td>
- <? } ?>
- <? while($row=mysql_fetch_assoc($query)){ ?>
- <tr align="center">
- <!-- display name -->
- <td align="left"><?= $row['name'] ?></td>
- <?
- //listtkan semua data student dlm array
- $student=array();
- $sql2="SELECT * FROM student WHERE name = '".$row['name']."'";
- $query2 = mysql_query($sql2);
- while($row2=mysql_fetch_assoc($query2)){
- $student[$row2['subject']]=$row2;
- }
- //cari maklumat mengikut subject
- for($j=0;$j<count($subject);$j++){
- if($student[$subject[$j]]['subject']){
- //jika ada display data
- echo '<td>'.$student[$subject[$j]]['mark'].'</td><td>'.$student[$subject[$j]]['grade'].'</td><td>'.$student[$subject[$j]]['attandance'].'</td>';
- }else{
- //jika takde displau empty cell
- echo '<td> </td><td> </td><td> </td>';
- }}
- ?>
- </tr>
- <? } ?>
- </table>
Copy the Code |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
boardmanager...cane nak cr source code cani ek...ader cadangan takk
|
|
|
|
|
|
|
|
guna javascript je
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
- <title>Untitled Document</title>
- <script type="text/javascript">
- function collapseAll(){
- var menuDiv = document.getElementById("menu");
- var divs = menuDiv.getElementsByTagName("div");
- var div;
- for (i = 0; i < divs.length; i++){
- div = divs[i];
- div.style.display = "none";
- }}
- function displayRow(Id){
- var row = document.getElementById("sub"+Id);
- if (row.style.display == '') row.style.display = 'none';
- else row.style.display = '';
- }
- </script>
- </head>
- <body onload="collapseAll();">
- <table width="200" border="1" id="menu">
- <tr>
- <td><a href="#" id="menu1" onclick="displayRow('menu1');">menu1</a>
- <div id="submenu1">
- <p>submenu1.1</p>
- <p>submenu1.2</p>
- <p>submenu1.3</p>
- </div>
- </td>
- </tr>
- <tr>
- <td><a href="#" id="menu2" onclick="displayRow('menu2');">menu2</a>
- <div id="submenu2">
- <p>submenu2.1</p>
- <p>submenu2.2</p>
- <p>submenu2.3</p>
- </div>
- </td>
- </tr>
- </table>
- </body>
- </html>
Copy the Code |
|
|
|
|
|
|
|
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? |
|
|
|
|
|
|
|
macam n ka???
- $sql = "SELECT mark FROM student ORDER BY mark desc LIMIT 5";
- $query = mysql_query($sql);
- while($row=mysql_fetch_assoc($query)){
- $i++;
- $mark+=$i<5?$row['mark']:$row['mark']*0.10;
- }
- echo $mark;
Copy the Code |
|
|
|
|
|
|
|
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:
Nama | Physic | Chemistry | Biology | English | Economics | Accounting | Best of 4 Subjects +10% (of 5th) | Kassim Patalon | 50 | 85 | 35 | 96 | 81 | 75 | x | Kassim Baba | 52 | 52 | 66 | 85 | 72 | 73 | x | Sadiq Segaraga | 68 | 96 | 85 | 73 | 73 | 62 | x | Abdul Wahab | 77 | 75 | 84 | 65 | 85 | 68 | x | Abdul Wahub | 54 | 42 | 72 | 81 | 44 | 92 | x |
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.
|
|
|
|
|
|
|
|
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
- //cari senarai subject dlm database
- $sql = "SELECT subject FROM student GROUP BY subject";
- $query = mysql_query($sql);
- while($row=mysql_fetch_assoc($query)){
- $subject[] = $row['subject'];
- }
- //listkan student name
- $sql = "SELECT name FROM student GROUP BY name";
- $query = mysql_query($sql);
- ?>
- <table border="1">
- <tr align="center">
- <td rowspan="2" width="200" align="left">Name</td>
- <!-- display subject name -->
- <? for($i=0;$i<count($subject);$i++){ ?>
- <td colspan="3"><?= $subject[$i] ?></td>
- <? } ?>
- <td rowspan="2" width="200">Best of 4 Subjects +10% (of 5th)</td>
- </tr>
- <!-- display other fields -->
- <? for($i=0;$i<count($subject);$i++){ ?>
- <td width="60" align="center">Mark</td>
- <td width="60" align="center">Grade</td>
- <td width="60" align="center">Attandance</td>
- <? } ?>
- <? while($row=mysql_fetch_assoc($query)){ ?>
- <tr align="center">
- <!-- display name -->
- <td align="left"><?= $row['name'] ?></td>
- <?
- //listtkan semua data student dlm array
- $i=0;
- $mark=0;
- $student=array();
- $sql2="SELECT * FROM student WHERE name = '".$row['name']."' ORDER BY mark DESC";
- $query2 = mysql_query($sql2);
- while($row2=mysql_fetch_assoc($query2)){
- $student[$row2['subject']]=$row2;
- $i++;
- if($i<5){
- $mark+=$row2['mark'].' ';
- }elseif($i==5){
- $mark+=$row2['mark']*0.10;
- }}
- //cari maklumat mengikut subject
- for($j=0;$j<count($subject);$j++){
- if($student[$subject[$j]]['subject']){
- //jika ada display data
- echo '<td>'.$student[$subject[$j]]['mark'].'</td><td>'.$student[$subject[$j]]['grade'].'</td><td>'.$student[$subject[$j]]['attandance'].'</td>';
- }else{
- //jika takde displau empty cell
- echo '<td> </td><td> </td><td> </td>';
- }}
- ?>
- <td><?= $mark ?></td>
- </tr>
- <? } ?>
- </table>
Copy the Code |
|
|
|
|
|
|
|
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..
Nama | Physic | Chemistry | Biology | English | Economics | Accounting | Best of 4 Subjects +10% (of 5th) | Kassim Patalon | 49 | 85 | 35 |
| 81 |
| x | Kassim Baba | 52 | 52 | 66 |
| 72 | 73 | x | Sadiq Segaraga | 68 |
| 85 | 73 | 73 | 62 | x | Abdul Wahab |
| 75 | 84 | 65 |
| 68 | x | Abdul Wahub | 54 | 42 | 72 | 81 | 44 | 92 | x | Number of students | 4 | 4 | 5 | 3 | 4 | 4 |
| Number of pass | 3 | 3 | 5 | 3 | 3 | 4 |
| % of passes | 75 | 75 | 100 | 100 | 75 | 100 |
|
Pass rate : >50 |
|
|
|
|
|
|
|
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.. |
|
|
|
|
|
|
|
peh... mencabar betul request ko....aku try gak
- $conn = mysql_connect($host, $user, $passwd) or die(mysql_error());
- $link = mysql_select_db($db, $conn) or die(mysql_error());
- $pass_mark = 50;
- function grade($mark){
- global $pass_mark;
- if(is_numeric($mark)){
- switch($mark):
- case $mark>=90:
- $grade='A';
- break;
- case $mark>=80&&$mark<90:
- $grade='B';
- break;
- case $mark>=70&&$mark<80:
- $grade='C';
- break;
- case $mark>=60&&$mark<70:
- $grade='D';
- break;
- case $mark>=50&&$mark<60:
- $grade='E';
- break;
- case $mark<$pass_mark:
- $grade='F';
- break;
- endswitch;
- return $grade;
- }
- }
- $sql = "SELECT subject FROM student GROUP BY subject";
- $query = mysql_query($sql);
- while($row=mysql_fetch_assoc($query)){
- $subject[] = $row['subject'];
- }
- $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";
- $query = mysql_query($sql);
- while($row=mysql_fetch_assoc($query)){
- $nos[$row['subject']] = $row;
- }
- $sql = "SELECT name FROM student GROUP BY name";
- $query = mysql_query($sql);
- ?>
- <table border="1">
- <tr>
- <td width="200">Name</td>
- <? for($i=0;$i<count($subject);$i++){ ?>
- <td colspan="2" align="center"><?= $subject[$i] ?></td>
- <? } ?>
- <td width="200">Best of 4 Subjects +10% (of 5th)</td>
- </tr>
- <? while($row=mysql_fetch_assoc($query)){ ?>
- <tr align="center">
- <td align="left"><?= $row['name'] ?></td>
- <?
- $i=0;
- $top5=0;
- $student=array();
- $sql2="SELECT * FROM student WHERE name = '".$row['name']."'";
- $query2 = mysql_query($sql2);
- while($row2=mysql_fetch_assoc($query2)){
- $student[$row2['subject']]=$row2;
- $i++;
- if($i<5)
- $top5+=$row2['mark'].' ';
- elseif($i==5)
- $top5+=$row2['mark']*0.10;
- }
- for($j=0;$j<count($subject);$j++){
- if($student[$subject[$j]]['subject']){
- $mark = $student[$subject[$j]]['mark'];
- if(!$mark)
- $td = '<td colspan="2"> </td>';
- elseif(grade($mark)=='F')
- $td = '<td style="color:#FF0000">'.$mark.'</td><td style="color:#FF0000">'.grade($mark).'</td>';
- else
- $td = '<td>'.$mark.'</td><td>'.grade($mark).'</td>';
- }else{
- $td = '<td colspan="2"> </td>';
- }
- $nos[$j]=$ns;
- echo $td;
- }
- ?>
- <td><?= number_format($top5,1) ?></td>
- </tr>
- <? } ?>
- <tr align="center">
- <td align="left">No of Student </td>
- <? for($s=0;$s<count($subject);$s++){ ?>
- <td colspan="2"><?= $nos[$subject[$s]]['nos'] ?></td>
- <? } ?>
- <td> </td>
- </tr>
- <tr align="center">
- <td align="left">No of Pass </td>
- <? for($s=0;$s<count($subject);$s++){ ?>
- <td colspan="2"><?= $nos[$subject[$s]]['nop'] ?></td>
- <? } ?>
- <td> </td>
- </tr>
- <tr align="center">
- <td align="left">% of passes</td>
- <? for($s=0;$s<count($subject);$s++){ ?>
- <td colspan="2"><?= number_format($nos[$subject[$s]]['nop']/$nos[$subject[$s]]['nos']*100,2) ?>%</td>
- <? } ?>
- <td> </td>
- </tr>
- </table>
Copy the Code
**tak rugi kedekut ilmu |
|
|
|
|
|
|
|
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- CREATE TABLE `test`.`student` (
- `student_id` int(5) NOT NULL auto_increment,
- `name` varchar(20) default NULL,
- `subject` varchar(20) default NULL,
- `mark` int(4) default NULL,
- `grade` varchar(4) default NULL,
- `attandance` int(4) default NULL,
- PRIMARY KEY (`student_id`)
- ) ENGINE=MyISAM AUTO_INCREMENT=39 DEFAULT CHARSET=latin1;
- --
- -- Dumping data for table `test`.`student`
- --
- INSERT INTO `test`.`student` VALUES (9,'Kassim Patalon','Physic',49,NULL,NULL),
- (10,'Kassim Baba','Physic',52,NULL,NULL),
- (11,'Sadiq Segaraga','Physic',68,NULL,NULL),
- (12,'Abdul Wahab','Physic',NULL,NULL,NULL),
- (13,'Abdul Wahub','Physic',54,NULL,NULL),
- (14,'Kassim Patalon','Chemistry',85,NULL,NULL),
- (15,'Kassim Baba','Chemistry',52,NULL,NULL),
- (16,'Sadiq Segaraga','Chemistry',NULL,NULL,NULL),
- (17,'Abdul Wahab','Chemistry',75,NULL,NULL),
- (18,'Abdul Wahub','Chemistry',42,NULL,NULL),
- (19,'Kassim Patalon','Biology',35,NULL,NULL),
- (20,'Kassim Baba','Biology',66,NULL,NULL),
- (21,'Sadiq Segaraga','Biology',85,NULL,NULL),
- (22,'Abdul Wahab','Biology',84,NULL,NULL),
- (23,'Abdul Wahub','Biology',72,NULL,NULL),
- (24,'Kassim Patalon','English',NULL,NULL,NULL),
- (25,'Kassim Baba','English',NULL,NULL,NULL),
- (26,'Sadiq Segaraga','English',73,NULL,NULL),
- (27,'Abdul Wahab','English',65,NULL,NULL),
- (28,'Abdul Wahub','English',81,NULL,NULL),
- (29,'Kassim Patalon','Economics',81,NULL,NULL),
- (30,'Kassim Baba','Economics',72,NULL,NULL);
- INSERT INTO `test`.`student` VALUES (31,'Sadiq Segaraga','Economics',73,NULL,NULL),
- (32,'Abdul Wahab','Economics',NULL,NULL,NULL),
- (33,'Abdul Wahub','Economics',44,NULL,NULL),
- (34,'Kassim Patalon','Accounting',NULL,NULL,NULL),
- (35,'Kassim Baba','Accounting',73,NULL,NULL),
- (36,'Sadiq Segaraga','Accounting',62,NULL,NULL),
- (37,'Abdul Wahab','Accounting',68,NULL,NULL),
- (38,'Abdul Wahub','Accounting',92,NULL,NULL);
Copy the Code
[ Last edited by BorderManager at 4-3-2009 02:25 AM ] |
|
|
|
|
|
|
|
board...cane nak buang yg table last nie...?
|
|
|
|
|
|
|
|
lorrr delete je la...
- <table border="1">
- <tr>
- <td width="200">Name</td>
- <? for($i=0;$i<count($subject);$i++){ ?>
- <td colspan="2" align="center"><?= $subject[$i] ?></td>
- <? } ?>
- </tr>
- <? while($row=mysql_fetch_assoc($query)){ ?>
- <tr align="center">
- <td align="left"><?= $row['name'] ?></td>
- <?
- $i=0;
- $top5=0;
- $student=array();
- $sql2="SELECT * FROM student WHERE name = '".$row['name']."'";
- $query2 = mysql_query($sql2);
- while($row2=mysql_fetch_assoc($query2)){
- $student[$row2['subject']]=$row2;
- }
- for($j=0;$j<count($subject);$j++){
- if($student[$subject[$j]]['subject']){
- $mark = $student[$subject[$j]]['mark'];
- if(!$mark)
- $td = '<td colspan="2"> </td>';
- elseif(grade($mark)=='F')
- $td = '<td style="color:#FF0000">'.$mark.'</td><td style="color:#FF0000">'.grade($mark).'</td>';
- else
- $td = '<td>'.$mark.'</td><td>'.grade($mark).'</td>';
- }else{
- $td = '<td colspan="2"> </td>';
- }
- $nos[$j]=$ns;
- echo $td;
- }
- ?>
- </tr>
- <? } ?>
- <tr align="center">
- <td align="left">No of Student </td>
- <? for($s=0;$s<count($subject);$s++){ ?>
- <td colspan="2"><?= $nos[$subject[$s]]['nos'] ?></td>
- <? } ?>
- </tr>
- <tr align="center">
- <td align="left">No of Pass </td>
- <? for($s=0;$s<count($subject);$s++){ ?>
- <td colspan="2"><?= $nos[$subject[$s]]['nop'] ?></td>
- <? } ?>
- </tr>
- <tr align="center">
- <td align="left">% of passes</td>
- <? for($s=0;$s<count($subject);$s++){ ?>
- <td colspan="2"><?= number_format($nos[$subject[$s]]['nop']/$nos[$subject[$s]]['nos']*100,2) ?>%</td>
- <? } ?>
- </tr>
- </table>
Copy the Code |
|
|
|
|
|
|
|
konpius nak delete mane 1...hihihih |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
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... |
|
|
|
|
|
|
|
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 ] |
|
|
|
|
|
|
|
baru nak jawap...dah ada org tolong jawap...thank you |
|
|
|
|
|
|
| |
|