<?php
	session_start();
	if (isset($_SESSION["admin"]["id"])) {

		if ($_GET) {

			include "../config/conf.php";
			$table = trim($_GET["table"]);
			$campos = "";
			if (isset($_GET["campos"])) $campos = trim($_GET["campos"]);
			if (!empty($table)) {

				$c;
				$x;
				if (!empty($campos)) {
					$c = explode(";",$campos);
				}
				if (is_array($c)) {
					$q = count($c);
					foreach ($c as $d) {
						if (empty($x)) $x = $d;
						else $x .= ",".$d;
					}
				}

				if (empty($x)) $x = "*";

				$sql = "select $x from $table order by 1";
		        $consulta = $db->prepare($sql); 
				$consulta->execute();
				while ($r = $consulta->fetch(PDO::FETCH_NUM)) {
					if (empty($campos)) {
						echo $r[0]." - ".$r[1];
					} else {
						$x = 0;
						foreach ($c as $d) {
							if ($x == 0) echo $r[$x]." - ";
							else echo $r[$x]." ";
							$x++;
						}
					}
				}
			}

		}

	}