statsUtils.lib.inc.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the statistic utility functions library for Chamilo.
  5. * Include/require it in your code to use its functionality.
  6. * @package chamilo.library
  7. * @deprecated
  8. */
  9. class StatsUtils
  10. {
  11. /**
  12. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  13. * @param sql : a sql query (as a string)
  14. * @desc return one result from a sql query (1 single result)
  15. */
  16. public static function getOneResult($sql)
  17. {
  18. $query = Database::query($sql);
  19. if ($query !== false) {
  20. $res = @Database::fetch_array($query, 'NUM');
  21. } else {
  22. $res = array();
  23. }
  24. return $res[0];
  25. }
  26. /**
  27. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  28. * @param sql : a sql query (as a string)
  29. * @desc Return many results of a query in a 1 column tab
  30. */
  31. public static function getManyResults1Col($sql)
  32. {
  33. $res = Database::query($sql);
  34. if ($res !== false) {
  35. $i = 0;
  36. while ($resA = Database::fetch_array($res, 'NUM')) {
  37. $resu[$i++] = $resA[0];
  38. }
  39. }
  40. return $resu;
  41. }
  42. /**
  43. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  44. * @param sql : a sql query (as a string)
  45. * @desc Return many results of a query
  46. */
  47. public static function getManyResults2Col($sql)
  48. {
  49. $res = Database::query($sql);
  50. if ($res !== false) {
  51. $i = 0;
  52. while ($resA = Database::fetch_array($res, 'NUM')) {
  53. $resu[$i][0] = $resA[0];
  54. $resu[$i][1] = $resA[1];
  55. $i++;
  56. }
  57. }
  58. return $resu;
  59. }
  60. /**
  61. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  62. * @param sql : a sql query (as a string)
  63. * @desc Return many results of a query in a 3 column tab
  64. * in $resu[$i][0], $resu[$i][1],$resu[$i][2]
  65. */
  66. public static function getManyResults3Col($sql)
  67. {
  68. $res = Database::query($sql);
  69. if ($res !== false) {
  70. $i = 0;
  71. while ($resA = Database::fetch_array($res, 'NUM')) {
  72. $resu[$i][0] = $resA[0];
  73. $resu[$i][1] = $resA[1];
  74. $resu[$i][2] = $resA[2];
  75. $i++;
  76. }
  77. }
  78. return $resu;
  79. }
  80. /**
  81. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  82. * @param sql : a sql query (as a string)
  83. * @desc Return many results of a query in a X column tab
  84. * in $resu[$i][0], $resu[$i][1],$resu[$i][2],...
  85. * this function is more 'standard' but use a little
  86. * more ressources
  87. * So I encourage to use the dedicated for 1, 2 or 3
  88. * columns of results
  89. */
  90. public static function getManyResultsXCol($sql, $X)
  91. {
  92. $res = Database::query($sql);
  93. if ($res !== false) {
  94. $i = 0;
  95. while ($resA = Database::fetch_array($res, 'NUM')) {
  96. for ($j = 0; $j < $X; $j++) {
  97. $resu[$i][$j] = $resA[$j];
  98. }
  99. $i++;
  100. }
  101. }
  102. return $resu;
  103. }
  104. }