Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    Problema mysql_fech_array

    Salve a tutti, ho un problema con questo semplicissimo script:

    Codice PHP:
    <?php

    include ("database/db_on.php");

    //Estraggo dal database tutto
    $query="SELECT * FROM tab1";
    $result=mysql_query($query);
    $rows=mysql_num_rows($result);

    //Ciclo che stampa tutto
    if (!$rows==0){
        while (
    $array=mysql_fetch_array($result)){
            print 
    $array['chiave'];
            print 
    $array['fonte'];
        }
    } else {
        print 
    "Non trovo nulla nel database.";
    }

    ?>
    In poche parole la query non tira giù nessun dato dal database e quindi mi printa Non trovo nulla nel Database. Non capisco proprio dove sia l'errore dato che sul database i dati ci sono (ho controllato con php my admin) e arrivano correttamente.

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    forse manca l'identificativo al database nel mysql_query:

    Che cosa ottieni in "database/db_on.php" ? Se ottieni il riferimento al database in una qualche variabile (tipo $db), dovresti passare anche $db a mysql_query
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    db on è questo:

    Codice PHP:
    $id=mysql_connect("****""*****""*****") or die("Errore nella connessione a MySql: ".mysql_error());
    mysql_select_db("****"$id) or die("Errore nella selezione del db: ".mysql_error()); 

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    perfetto allora le query eseguile così
    codice:
    $query = "SELECT lbla blah...";
    $result = mysql_query($query,$id);
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  5. #5
    purtroppo non cambia nulla, viene sempre printato "non trovo nulla nel database"

  6. #6
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Allora la query è sbagliata oppure non recupera davvero niente.

    e così?

    codice:
    $query = "SELECT lbla blah...";
    $result = mysql_query($query,$id) or die(mysql_error());
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  7. #7
    mettendo la query così:

    Codice PHP:
    $result=mysql_query($query$id) or die("Errore: ".mysql_error()); 
    stampa a schermo --> "Errore: "

  8. #8
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Allora, visto che stiamo facendo debug, metti come prima istruzione php della pagina:

    codice:
    error_reporting(E_ALL);
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  9. #9
    uh l'errore era l'include.. aveva un indrizzo errato

    grazie 1000

  10. #10
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    apposto.
    Ciao.
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

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 © 2025 vBulletin Solutions, Inc. All rights reserved.