Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [php] ciclo while

  1. #1

    [php] ciclo while

    mi da errore Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/raptxt/public_html/commenti.php on line 26 (la riga del while)

    e mi mostra solo l'ultimo elemento della tabella del db e non tutti...

    Codice PHP:
    <?php session_start();

    // Get the default templates, Includes and Database connections
    include("header.php");

    $tpl->assignInclude("content""themes/$themes/tpl/commenti.tpl");

    // Prepare the template
    $tpl->prepare();

    // Get the menu items and links
    include("menu.php");

    // Assign needed values
    $tpl->assignGlobal("theme"$themes);
    $tpl->assignGlobal("imgfolder""http://raptesti.interfree.it");
    $tpl->assign("version"$version);
    $tpl->assign("type"$_GET['art']);
    $a=1;

    // The MySQL command to run
    $select "SELECT * FROM commenti WHERE alb=$alb ORDER BY data, uid ASC";

    // Run the query
    $data mysql_db_query($sql['data'], $select) or die("commenti Failed!");
    while (
    $row mysql_fetch_array($data))
       {
          
    // Get all the fields
          
    $uid $row['uid'];
          
    $nome $row['nome'];
          
    $data $row['data'];
          
    $commento $row['commento'];
          echo
    "$nome $commento";
          
    $nome=stripslashes($nome);
          
    $commento=stripslashes($commento);
          
    $commento=nl2br($commento);
          
    $rap="";
          
    if (
    $nome =="" || $commento=""){
    $nome="RapTxt"$commento="nessun commento inserito. Inserisci tu il primo!";}


          
    // Set the values to template variables
          
    $tpl->newBlock("commenti");
          
    $tpl->assign("uid"$uid);
          
    $tpl->assign("nome"$nome);
          
    $tpl->assign("commento"$commento);
          
    $tpl->assign("data"$data);
          
    $tpl->assign("num"$a);
          
    $a++;
        }

    // Print the result
    $tpl->printToScreen();

    ?>

  2. #2
    Utente di HTML.it L'avatar di JHammer
    Registrato dal
    Sep 2004
    Messaggi
    754
    Intanto puoi vedere una descrizione dell'errore mysql stampandola...

    echo mysql_error();

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.