- Home
- Categorie
- Coding e Sistemistica
- PHP
- stampare news
-
quindi faccio così??
[PHP]id=$_GET['id'];
$testo=@mysql_query("SELECT * FROM news ORDER BY id_news DESC limit 1 ");
if(mysql_num_rows($testo)<1)
exit('Non è possibile trovare la news.');$testo=mysql_fetch_array($testo);
$titolo=$testo['titolo'];
$text=$testo['testo'];
$datas=$testo['data'];
$text=htmlspecialchars($text);[/PHP]
-
si dovrebbe andare
-
no...mi da errore...non va!!!
-
quale?
postate anche l'errore per cortesia!
-
@massimux said:
quale?
postate anche l'errore per cortesia!Questo:
[PHP]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Programmi\EasyPHP 2.0b1\www\tapsos\index.php on line 24
Non è possibile trovare la news.[/PHP]Ciau
-
[PHP]id=$_GET['id'];
$testo=@mysql_query("SELECT * FROM news ORDER BY id_news DESC limit 1 ");
$num=mysql_num_rows($testo);
if ($num<1){
echo"Non ci sono news";
exit();
}
$testoa=mysql_fetch_array($testo);
$titolo=$testoa['titolo'];
$text=$testoa['testo'];
$datas=$testoa['data'];
$text=htmlspecialchars($text);[/PHP]scrivi il codice in questo modo... altrimenti con almeno un record nel database scrivi questo e dimmi che ti mostra
[PHP]id=$_GET['id'];
$testo=@mysql_query("SELECT * FROM news ORDER BY id_news DESC limit 1 ");$testoa=mysql_fetch_array($testo);
$titolo=$testoa['titolo'];
$text=$testoa['testo'];
$datas=$testoa['data'];
$text=htmlspecialchars($text);[/PHP]
-
Questi gli errori.
Primo codice:**Warning**: mysql_num_rows(): supplied argument is not a valid MySQL result resource in **C:\Programmi\EasyPHP 2.0b1\www\tapsos\index.php** on line **24** Non ci sono news
Secondo codice:
**Warning**: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in **C:\Programmi\EasyPHP 2.0b1\www\tapsos\index.php** on line **24**
Ciao!
-
Ti Prende le ultime due:
[PHP]$query = "select * from news ORDER BY id DESC limit 2";
$dbResult = mysql_query($query, $db);
$AffectedRows = mysql_affected_rows($db);
while ($dati = mysql_fetch_array($dbResult, MYSQL_ASSOC) and $i < 2) {
$i++;
....[/PHP]
facilmente ottimizzabile se devi prenderne di più..
Vai tranquillo che funziona.
-
@MZ said:
Ti Prende le ultime due:
[php]$query = "select * from news ORDER BY id DESC limit 2";
$dbResult = mysql_query($query, $db);
$AffectedRows = mysql_affected_rows($db);
while ($dati = mysql_fetch_array($dbResult, MYSQL_ASSOC) and $i < 2) {
$i++;
....[/php]
o mamma...ke vuol dire??che cosa è??
-
Ma io che cosa faccio con questo codice?? A me serve visualizzare una sola news...quella con id più vekkio...come fare dato ke (come si legge sopra) mi da errore??
[php]$query = "select * from news ORDER BY id DESC limit 2";
$dbResult = mysql_query($query, $db);
$AffectedRows = mysql_affected_rows($db);
while ($dati = mysql_fetch_array($dbResult, MYSQL_ASSOC) and $i < 2) {
$i++;
....[/php]
-
mi devo scusare con tutta la redazione e tutti gli utenti di questa discussione. Gli errori erano causati da una mia dimenticanza...
Mi ero dimenticato la connessione al DATABASE.....
Ciau!
-
no problem.... l'importante e' che ci siamo riusciti