Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Funzione che cancella gli spazi finali di una stringa
- *
- * @param String $string
- *
- * @return String Una stringa uguale a quella passata in input ma senza spazi finali
- */
- function cancellaSpaziFinali($string) {
- $len = strlen($string)-1;
- for ($i=$len; $i>0; $i--)
- if ($string[$i] != " ")
- break;
- return substr($string, 0, $i + 1);
- }
- $query = $_GET[QUERY];
- $db = pg_connect("host=127.0.0.1 dbname=ingsw12_03 user=postgres password=poppe);
- if ($db) {
- $result = pg_query($query);
- if (!$result) {
- echo "Problem with query " . $query . "<br/>";
- echo pg_last_error();
- exit();
- }
- $output = "";
- /* per ogni riga della tabella */
- while($arr = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
- /* leggo le chiavi della riga */
- $keys = array_keys($arr);
- /* se รจ il primo ciclo del while scrivo nella prima linea dell'output le chiavi usate nella tabella */
- if ($output == "") {
- for ($i=0; $i<count($keys); $i++)
- $output .= $keys[$i] . "<tc>";
- $output .= "<tr>\n";
- }
- /* per ogni colonna della tabella */
- for ($i=0; $i<count($keys); $i++) {
- /* leggo l'item e lo aggiungo all'output */
- if ($i == count($keys) - 1)
- $output .= cancellaSpaziFinali($arr[$keys[$i]]);
- else
- $output .= cancellaSpaziFinali($arr[$keys[$i]]) . "<tc>";
- }
- $output .= "<tr>\n";
- }
- //echo("<pre><xmp>");
- header('Content-type: text/plain');
- echo($output);
- //echo("</xmp></pre>");
- }
- ?>
Add Comment
Please, Sign In to add comment