Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. function SQLResultTable($Query)
  2. {
  3. $host = "localhost";
  4. $user = "root";
  5. $pass = "";
  6. $db = "Quality_Monitoring";
  7. $link = mysql_connect($host, $user, $pass) or die('Could not connect: ' . mysql_error()); //build MySQL Link
  8. mysql_select_db($db) or die('Could not select database'); //select database
  9. $Table = ""; //initialize table variable
  10.  
  11. $Table.= "<table id='Table1' border='1' style="border-collapse: collapse; text-align: center; font-size: 10px; cellspacing: 5px; ">"; //Open HTML Table
  12.  
  13. $Result = mysql_query($Query); //Execute the query
  14. if(mysql_error())
  15. {
  16. $Table.= "<tr><td>MySQL ERROR: " . mysql_error() . "</td></tr>";
  17. }
  18. else
  19. {
  20. //Header Row with Field Names
  21. $NumFields = mysql_num_fields($Result);
  22. $Table.= "<tr style="background-color: #000066; text-align: center; color: #FFFFFF;">";
  23. for ($i=0; $i < $NumFields; $i++)
  24. {
  25. $Table.= "<th>" . mysql_field_name($Result, $i) . "</th>";
  26. }
  27. $Table.= "</tr>";
  28.  
  29. //Loop thru results
  30. $RowCt = 0; //Row Counter
  31. while($Row = mysql_fetch_assoc($Result))
  32. {
  33. //Alternate colors for rows
  34. if($RowCt++ % 2 == 0) $Style = "background-color: #CCCCCC;";
  35. else $Style = "background-color: #FFFFFF;";
  36.  
  37. $Table.= "<tr style="$Style">";
  38. //Loop thru each field
  39. foreach($Row as $field => $value)
  40. {
  41. $Table.= "<td>$value</td>";
  42. }
  43. $Table.= "</tr>";
  44. }
  45. // $Table.= "<tr style="background-color: #000066; color: #FFFFFF;"><td colspan='$NumFields'>Query Returned " . mysql_num_rows($Result) . " records</td></tr>";
  46. }
  47. $Table.= "</table>";
  48.  
  49. return $Table;
  50.  
  51. }
  52.  
  53. //Header Row with Field Names
  54. $NumFields = mysql_num_fields($Result);
  55. $Table.= "<tr style="background-color: #000066; text-align: center; color: #FFFFFF;">";
  56. for ($i=0; $i < $NumFields; $i++)
  57. {
  58. $Table.= "<th>" . mysql_field_name($Result, $i) . "</th>";
  59. }
  60. $Table.= "</tr>";
  61.  
  62. function SQLResultTable($Query)
  63. {
  64. $host = "localhost";
  65. $user = "root";
  66. $pass = "";
  67. $db = "Quality_Monitoring";
  68. $link = mysql_connect($host, $user, $pass) or die('Could not connect: ' . mysql_error()); //build MySQL Link
  69. mysql_select_db($db) or die('Could not select database'); //select database
  70. $Table = ""; //initialize table variable
  71.  
  72. $Table.= "<table id='Table1' border='1' style="border-collapse: collapse; text-align: center; font-size: 10px; cellspacing: 5px; ">"; //Open HTML Table
  73.  
  74. $Result = mysql_query($Query); //Execute the query
  75. if(mysql_error())
  76. {
  77. $Table.= "<tr><td>MySQL ERROR: " . mysql_error() . "</td></tr>";
  78. }
  79. else
  80. {
  81. //Loop thru results
  82. $RowCt = 0; //Row Counter
  83. while($Row = mysql_fetch_assoc($Result))
  84. {
  85. //Alternate colors for rows
  86. if($RowCt++ % 2 == 0) $Style = "background-color: #CCCCCC;";
  87. else $Style = "background-color: #FFFFFF;";
  88.  
  89. $Table.= "<tr style="$Style">";
  90. //Loop thru each field
  91. foreach($Row as $field => $value)
  92. {
  93. $Table.= "<td>$value</td>";
  94. }
  95. $Table.= "</tr>";
  96. }
  97. // $Table.= "<tr style="background-color: #000066; color: #FFFFFF;"><td colspan='$NumFields'>Query Returned " . mysql_num_rows($Result) . " records</td></tr>";
  98. }
  99. $Table.= "</table>";
  100.  
  101. return $Table;
  102.  
  103. }
  104.  
  105. function SQLResultTable($Query)
  106. {
  107. $host = "localhost";
  108. $user = "root";
  109. $pass = "";
  110. $db = "Quality_Monitoring";
  111. $link = mysql_connect($host, $user, $pass) or die('Could not connect: ' . mysql_error()); //build MySQL Link
  112. mysql_select_db($db) or die('Could not select database'); //select database
  113. $Table = ""; //initialize table variable
  114.  
  115. $Table.= "<table id='Table1' border='1' style="border-collapse: collapse; text-align: center; font-size: 10px; cellspacing: 5px; ">"; //Open HTML Table
  116.  
  117. $Result = mysql_query($Query); //Execute the query
  118. if(mysql_error())
  119. {
  120. $Table.= "<tr><td>MySQL ERROR: " . mysql_error() . "</td></tr>";
  121. }
  122. else
  123. {
  124. //Header Row with Field Names
  125. $NumFields = mysql_num_fields($Result);
  126. $Table.= "<tr style="background-color: #000066; text-align: center; color: #FFFFFF;">";
  127. for ($i=0; $i < $NumFields; $i++)
  128. {
  129. $Table.= "<th>" . mysql_field_name($Result, $i) . "</th>";
  130. }
  131. $Table.= "</tr>";
  132.  
  133. //Loop thru results
  134. $RowCt = 0; //Row Counter
  135. while($Row = mysql_fetch_assoc($Result))
  136. {
  137. //Alternate colors for rows
  138. if($RowCt!=0)
  139. {
  140. if($RowCt % 2 == 0) $Style = "background-color: #CCCCCC;";
  141. else $Style = "background-color: #FFFFFF;";
  142.  
  143. $Table.= "<tr style="$Style">";
  144. //Loop thru each field
  145. foreach($Row as $field => $value)
  146. {
  147. $Table.= "<td>$value</td>";
  148. }
  149. $Table.= "</tr>";
  150. }
  151. $RowCt++;
  152. }
  153. // $Table.= "<tr style="background-color: #000066; color: #FFFFFF;"><td colspan='$NumFields'>Query Returned " . mysql_num_rows($Result) . " records</td></tr>";
  154. }
  155. $Table.= "</table>";
  156.  
  157. return $Table;
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement