Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1.                         <?php
  2.                             $total = get_query('Curs', 'cursos', 'NULL', 'NULL', 1);    //retorna el numero total de cursos
  3.                             $mostrat = get_query('Curs', 'cursos', 'NULL', 'NULL', 2);
  4.                            
  5.                             for ($i = 0; $i<= $total; $i++)
  6.                             {
  7.                                 echo "<option>$mostrat[$i]</option>";                      
  8.                             }
  9.                         ?>
  10.  
  11.     function get_query($selection, $table, $column, $data, $option)
  12.     {
  13.         $configs = include("config.php");   //archivo de configuraciones basico
  14.  
  15.         $link = mysqli_connect($configs['ip'], $configs['username'], $configs['password'], $configs['bbdd']);
  16.  
  17.         switch ($option)
  18.         {
  19.             case 0:
  20.                 $sql = "SELECT $selection FROM $table WHERE $column = '$data'";
  21.                 break;
  22.             case 1:
  23.                 $sql = "SELECT COUNT(*) as $selection from $table";
  24.                 break;
  25.             case 2:
  26.                 $sql = "SELECT $selection FROM $table";
  27.                 break;
  28.         }
  29.  
  30.         $result = mysqli_fetch_assoc(mysqli_query($link, $sql));
  31.  
  32.             return $result[$selection];
  33.  
  34.         mysqli_close($link);
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement