estrazione dati

  • Creatore Discussione Creatore Discussione Sargon
  • Data di inizio Data di inizio

Sargon

Utente Attivo
22 Mar 2012
45
0
0
Ciao a tutti!

Ho un quesito da porvi... molto banale come sempre... ma sono alle prime armi.
Devo estrarre da una tabella dei valori e visualizzarli; devo estrarre solamente quelli pieni e non quelli vuoti... come faccio?
grassie!
vi posto il codice :dipser:

PHP:
$webpage = basename($_SERVER['PHP_SELF']);
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$result = mysql_query("select * FROM  jjj ORDER BY id ASC");
$max_results = 20;//
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$from = (($page * $max_results) - $max_results);
$result=mysql_query("select * FROM jjj ORDER BY id ASC LIMIT $from, $max_results ");

while ($i = mysql_fetch_array($result))
{
echo"".
 
ciao
non ho capito bene, ma se estrai i valori così come sono poi stampi solo quelli pieni
if campo !="" echo campo

Ciao!
allora ho una tabella composta dai classici campi
id
Autore
titolo

faccio un esempio.
id 1 id 2
Autore Carlo Autore Mario
titolo esempio titolo (non c'è)

Prendendo il campo titolo come riferimento vorrei che mi comparisse sullo schermo il record che presenta il campo titolo con un valore..
quindi il primo

stampa.
id 1 Autore Carlo titolo esempio.

Vi ringrazio infinitamente!:tifoso::tifoso::tifoso:
 
ciao
puoi provare cosi
PHP:
<?php
//...
while ($i = mysql_fetch_array($result)){
	if($i['titolo'] !=""){
		echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
	}
}
//....
?>
oppure prova a modificare le query
PHP:
<?php
//....
$result = mysql_query("select * FROM  jjj  WHERE titolo <> '' ORDER BY id ASC");
$max_results = 20;//
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$from = (($page * $max_results) - $max_results);
$result=mysql_query("select * FROM jjj WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results "); 
while ($i = mysql_fetch_array($result)){
	echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
}
//....
?>
se funzia (prova) il secondo metodo è migliore
 
ciao
puoi provare cosi
PHP:
<?php
//...
while ($i = mysql_fetch_array($result)){
	if($i['titolo'] !=""){
		echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
	}
}
//....
?>
oppure prova a modificare le query
PHP:
<?php
//....
$result = mysql_query("select * FROM  jjj  WHERE titolo <> '' ORDER BY id ASC");
$max_results = 20;//
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$from = (($page * $max_results) - $max_results);
$result=mysql_query("select * FROM jjj WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results "); 
while ($i = mysql_fetch_array($result)){
	echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
}
//....
?>
se funzia (prova) il secondo metodo è migliore



non fa errore però... in entrambi i casi... non viene visualizzato nessun dato..:dipser:
 
ciao
partiamo dalla prima (poi per la seconda guardo meglio), prova a scrivere
PHP:
 <?php
//...
while ($i = mysql_fetch_array($result)){
    //if($i['titolo'] !=""){
        echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
    //}
}
//....
?>
cioè a commetare l'if, se non ti stampa nulla l'errore è a monte, o i nomi dei campi o nelle query
 
ciao
per la seconda
dividi le query e metti dei var_dump (puoi fare lo stesso anche con la prima)
PHP:
<?php
//....
$q_1="SELECT * FROM  jjj  WHERE titolo <> '' ORDER BY id ASC";
var_dump($q_1);//qui verifichi che la query venga scritta come vuoi tu
$result = mysql_query($q_1);
var_dump($result); // se ti da bool FALSE c'è un errore probabilmente nei nomi
$max_results = 20;//
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$from = (($page * $max_results) - $max_results);
$q_2="select * FROM jjj WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results ";
var_dump($q_2);
$result=mysql_query($q_2);// come prima
var_dump($result);
while ($i = mysql_fetch_array($result)){
    echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
}
//....
?>
altro tentativo al posto di <> prova a mettere !=
 
ciao
per la seconda
dividi le query e metti dei var_dump (puoi fare lo stesso anche con la prima)
PHP:
<?php
//....
$q_1="SELECT * FROM  jjj  WHERE titolo <> '' ORDER BY id ASC";
var_dump($q_1);//qui verifichi che la query venga scritta come vuoi tu
$result = mysql_query($q_1);
var_dump($result); // se ti da bool FALSE c'è un errore probabilmente nei nomi
$max_results = 20;//
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$from = (($page * $max_results) - $max_results);
$q_2="select * FROM jjj WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results ";
var_dump($q_2);
$result=mysql_query($q_2);// come prima
var_dump($result);
while ($i = mysql_fetch_array($result)){
    echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
}
//....
?>
altro tentativo al posto di <> prova a mettere !=


e si.... mi da come errore bool FALSE ... secondo te quale è il motivo?? grazie mille!
 
ciao,
stampa l'errore che ti fornisce mysql
PHP:
if (!$result) {
    echo $q_1 . "<br/>" . mysql_error();
}
dovresti riuscire a indentificare il problema dal messaggio
 
ciao,
stampa l'errore che ti fornisce mysql
PHP:
if (!$result) {
    echo $q_1 . "<br/>" . mysql_error();
}
dovresti riuscire a indentificare il problema dal messaggio

ecc la scritta che mi compare:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.



suggerimenti? :(
 
ciao
dividi le query e metti dei var dump in modo da vedere cosa succede (te ne divido una, l'altra uguale)
PHP:
<?php
//....
$query="SELECT * FROM  jjj ORDER BY id ASC";
var_dump($query);//qui vedi se viene scritta come si deve
$result = mysql_query($query);
var_dump($result);//qui vede se la query va a buon fine, resuorce... si, false no
//....
?>
eventualmente posta quello che ti risulta

edit
scusa quale script stai usando?
 
Ultima modifica:
ciao
se l'errore ti avviene alla seconda query, prova.
(ho fatto delle googlate e ho trovato almeno 4 versioni diverse (due già indicate))
l'unica e provarle

$q_2="SELECT * FROM jjj WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results ";
$q_2="SELECT * FROM jjj WHERE titolo != '' ORDER BY id ASC LIMIT $from, $max_results ";
$q_2="SELECT * FROM jjj WHERE titolo IS NOT EMPTY ORDER BY id ASC LIMIT $from, $max_results ";
$q_2="SELECT * FROM jjj WHERE !(ISNULL([titolo])) ORDER BY id ASC LIMIT $from, $max_results ";

comunque non hai risposto una cosa: mettendo un semplice while alla prima o seconda query
PHP:
 <?php
//...dati di connessione
$result = mysql_query("SELECT * FROM  jjj ORDER BY id ASC"); 
while ($i = mysql_fetch_array($result)){
        echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
}
//....
?>
ti ha dato qualcosa? perche se non ti risulta nulla con questo semplice script (provalo a parte) un errore che puo essere comune è
nella querry hai scritto jjj ma la tabella si chiama Jjj (analogo per i nomi dei campi, es Id e id)
 
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
a me non sembra un errore di sintassi della query ma un erroredi permessi

ho trovato questa discussione
http://forum.joomla.it/index.php?topic=121122.0
 
ciao
se l'errore ti avviene alla seconda query, prova.
(ho fatto delle googlate e ho trovato almeno 4 versioni diverse (due già indicate))
l'unica e provarle

$q_2="SELECT * FROM jjj WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results ";
$q_2="SELECT * FROM jjj WHERE titolo != '' ORDER BY id ASC LIMIT $from, $max_results ";
$q_2="SELECT * FROM jjj WHERE titolo IS NOT EMPTY ORDER BY id ASC LIMIT $from, $max_results ";
$q_2="SELECT * FROM jjj WHERE !(ISNULL([titolo])) ORDER BY id ASC LIMIT $from, $max_results ";

comunque non hai risposto una cosa: mettendo un semplice while alla prima o seconda query
PHP:
 <?php
//...dati di connessione
$result = mysql_query("SELECT * FROM  jjj ORDER BY id ASC"); 
while ($i = mysql_fetch_array($result)){
        echo $i['id'].") autore: ".$i['autore'].", titolo: ".$i['titolo']."<br />";
}
//....
?>
ti ha dato qualcosa? perche se non ti risulta nulla con questo semplice script (provalo a parte) un errore che puo essere comune è
nella querry hai scritto jjj ma la tabella si chiama Jjj (analogo per i nomi dei campi, es Id e id)


GRAZIEEEE INGHIPPO RISOLTO ANCHE QUESTA VOLTA !!!!! vi ringrazio infinitamente!!!
 
ciao
per i posteri: come hai risolto?

$webpage = basename($_SERVER['PHP_SELF']);
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$result = mysql_query("select * FROM database ORDER BY id ASC");
$max_results = 20;//
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$from = (($page * $max_results) - $max_results);
$result = mysql_query("SELECT * FROM database WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results");
while ($i = mysql_fetch_array($result)){
echo "<p>". "<b>"."Id:"."</b>". $i['id']."&nbsp;"."&nbsp;"."<b>"." Title: "."</b>".$i['title']."&nbsp;"."&nbsp;". " Author: "."</b>".$i['author'].
"</br>";
}


la query incriminata.

$result = mysql_query("SELECT * FROM database WHERE titolo <> '' ORDER BY id ASC LIMIT $from, $max_results");



Grazie ancora... al prossimo quesito! (che vi posterò tra poco....)
 

Discussioni simili