reenadak

Taking multidimentional data in a array using mysql query

Jul 30th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. $result = mysql_query("SELECT atten_hour, atten_date, mba_manpower_master.designation FROM ".TBL_MAIN." LEFT JOIN mba_manpower_master on mba_attendance.eid = mba_manpower_master.mid ");
  2. if (!$result) {
  3. die("Query to show fields from table failed");
  4. }
  5. $fields_num = mysql_num_fields($result);
  6. echo "<h1>Table: {$table}</h1>";
  7. echo "<table border='1' cellspacing='0' cellpadding='3'><tr>";
  8. // printing table headers
  9. for($i = 0; $i < $fields_num; $i++) {
  10. $field = mysql_fetch_field($result);
  11. echo "<td>{$field->name}</td>";
  12. }
  13. echo "</tr>n";
  14. // printing table rows
  15. while ($row = mysql_fetch_row($result)) {
  16. echo "<tr>";
  17.  
  18. $hour_master_raw[] = array($row);
  19.  
  20. // $row is array... foreach( .. ) puts every element
  21. // of $row to $cell variable
  22. foreach($row as $cell)
  23. if($cell) echo "<td>$cell</td>";
  24. else echo "<td>&nbsp;</td>";
  25. echo "</tr>n";
  26. }
  27. mysql_free_result($result);
  28.  
  29.  
  30. // var_dump( $hour_master_raw);
  31.  
  32. $designation = array(
  33. "Fitter",
  34. "Grinder man",
  35. "Khalasi",
  36. "Rigger",
  37. "Supervisor",
  38. "Welder"
  39. );
  40.  
  41. foreach ( $designation as $d ){
  42.  
  43. foreach($hour_master_raw as $entry)
  44. {
  45. foreach($entry as $x)
  46. {
  47. // $x[2] // Desig
  48. // $x[1] // Date
  49. // $x[0] // hour
  50. if($x[2] == $d)
  51. {
  52. if(array_key_exists($x[1],$hour_master)){
  53.  
  54. $past_hour = $hour_master[$x[1]];
  55.  
  56. $hour_master[$x[1]] = $x[0] + $past_hour;
  57.  
  58. } else {
  59. $hour_master[$x[1]] = $x[0];
  60. }
  61. }
  62. }
  63. }
  64. $att_data_master[$d] = $hour_master;
  65. }
  66.  
  67. var_dump($att_data_master);
  68. unset($att_data_master);
Advertisement
Add Comment
Please, Sign In to add comment