estrazione dati

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"".
 

Sargon

Utente Attivo
22 Mar 2012
45
0
0
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:
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
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
 

Sargon

Utente Attivo
22 Mar 2012
45
0
0
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:
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
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
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
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 !=
 

Sargon

Utente Attivo
22 Mar 2012
45
0
0
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!
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
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
 

Sargon

Utente Attivo
22 Mar 2012
45
0
0
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? :(
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
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:

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
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)
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
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
 

Sargon

Utente Attivo
22 Mar 2012
45
0
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!!!
 

Sargon

Utente Attivo
22 Mar 2012
45
0
0
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
Autore Titolo Forum Risposte Data
E Progressbar estrazione dati da tabella mySQL Ajax 9
L Estrazione dati php Database 6
L Estrazione dati casuali non doppioni MySQL 1
D Chiave unica in estrazione dati da array php PHP 0
ronny1710 Estrazione Dati Tessera Sanitaria .NET Framework 1
creatorweb [PHP] estrazione ciclica dati con 2 dati alla volta PHP 2
Gigi87 [PHP] Estrazione dati da forum o da social network PHP 1
L estrazione dati da mysql in php e salvataggio in cartella del server PHP 51
E [PHP] estrazione dati in modo non continuativo PHP 1
C Estrazione Dati da Pagine Gialle PHP 0
A Estrazione dati da tabella sql MySQL 27
T Codice per estrazione dati da db PHP 4
L estrazione dati per login PHP 0
W Estrazione dati da DB PHP 20
L Estrazione dati per settimana. PHP 13
L estrazione dati e immagini in contemporanea PHP 4
M estrazione dati casuali da database Database 0
C [PHP][MY SQL] - Estrazione dati database tramite form PHP 8
G estrazione dati da DB tramite PHP errore time out PHP 2
B Estrazione dati utente loggato MySQL 1
W Estrazione dati DB da lista MySQL 1
M Connessione Database ed estrazione dati Javascript 6
A [risolto] Istruzione per estrazione di dati casuali dal db PHP 25
B Estrazione dati Classic ASP 3
U Estrazione dati da un db con un menu selezione in cascata PHP 6
A Estrazione dati da file.html PHP 8
G estrazione dati da xml ed inserimento in db PHP 0
P Menu a discesa con estrazione dati da datbase mysql PHP 21
M problema con estrazione dati da più tabelle MySQL 1
A problema: estrazione dati da query mysql e assegnazione ad una variabile PHP 2
L Estrazione dati PHP 32
M caratteri speciali ed estrazione dati Database 4
L Estrazione dati da 2 tabelle non relazionate Classic ASP 26
R Aiuto estrazione dati Database 0
G estrazione dati da più record in un solo nuovo campo Database 0
E Difficile estrazione dati da tabella PHP 3
K Estrazione di più risultati da tabelle correlate PHP 5
L Estrazione valori max su più campi MySQL 4
M [PHP] Estrazione random con nomi presi dal db PHP 22
gandalf1959 Estrazione e visualizzazione del simbolo dell'euro php/mysqli PHP 0
F Estrazione Email di persone selezionate e attive / facebook + invio di massa! Annunci servizi di Social Media Marketing 0
V Estrazione di una singola banda da file multi banda (RGB) con Python Programmazione 0
O [PHP] problema estrazione immagine da db PHP 12
V [PHP] Estrazione con SQL PHP 1
M [MS Access] Estrazione record multipli MS Access 1
S [PHP] estrazione dal DB complicata PHP 7
asevenx [Javascript] Estrazione dal database di un valore in base ad una scelta Javascript 7
S Php e mysql, estrazione da una tabella e inserimento in un'altra tabella PHP 14
P Probelma estrazione stringa PHP 5
L Estrazione Articoli Random da Tabella senza doppioni PHP 1

Discussioni simili