Visualizzazione dei risultati da 1 a 7 su 7

Discussione: errore query

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2015
    Messaggi
    6

    errore query

    ciao a tutti!

    Codice PHP:
    <?php
                                                                    mysql_query
    ("SET CHARACTER SET utf8");
                                                                    
    mysql_query("SET NAMES utf8");
                                                                    
    $rowsPerPage 20;
                                                                    
    $pageNum 1;
                                                                    if (isset(
    $_GET['page'])) {
                                                                        
    $pageNum $_GET['page'];
                                                                    }
                                                                    
    $offset = ($pageNum 1) * $rowsPerPage;
                                                                    
    $lettera=$_REQUEST['lettera'];
                                                                    if (
    $lettera == NULL) {
                                                                        
    $lettera '';
                                                                    } else {
                                                                        
    $lettera=$_REQUEST['lettera'];
                                                                    }
                                                                    if (
    $spec == NULL and $lettera == NULL and $tipo_medico == 1) {
                                                                        
    $Sqlqr_gl="select * from medici_chirurghi where cognome != '' order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
                                                                        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi where cognome != ''";
                                                                    } else if (
    $spec == NULL and $lettera != NULL and $tipo_medico == 1) {
                                                                        
    $Sqlqr_gl="select * from medici_chirurghi where cognome != '' and cognome LIKE '$lettera%' order by cognome LIMIT $offset$rowsPerPage";
                                                                        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi where cognome != '' and cognome LIKE '$lettera%'";
                                                                    } else if (
    $spec != NULL and $tipo_medico == 1) {
                                                                        
    $Sqlqr_gl="select m.* from medici_chirurghi m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
                                                                        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola";
                                                                    } else if (
    $spec == NULL and $lettera == NULL and $tipo_medico == 2) {
                                                                        
    $Sqlqr_gl="select * from medici_odontoiatri where cognome != '' order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
                                                                        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_odontoiatri where cognome != ''";
                                                                    } else if (
    $spec == NULL and $lettera != NULL and $tipo_medico == 2) {
                                                                        
    $Sqlqr_gl="select * from medici_odontoiatri where cognome != '' and cognome LIKE '$lettera%' order by cognome  LIMIT $offset$rowsPerPage";
                                                                        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_odontoiatri where cognome != '' and cognome LIKE '$lettera%'";
                                                                    } else if (
    $spec != NULL  and $tipo_medico == 2) {
                                                                        
    $Sqlqr_gl="select m.* from medici_odontoiatri m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
                                                                        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_odontoiatri m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola";
                                                                    }
                                                                    echo 
    "<div style=display:none>".$Sqlqr_gl."</div>";
                                                                    
    $qr_gl=mysql_query($Sqlqr_gl,$connessione)or die(mysql_error());
                                                                    while(
    $r_gl=mysql_fetch_array($qr_gl,MYSQL_ASSOC)) {
                                                                        if (
    $r_gl['cognome'] != NULL) {
                                                                            
    ?>
    Codice PHP:
    <?php 
                                                            
    if ($idmenu == '44') {
                                                                
    $tipo_medico '2';
                                                            } else if (
    $idmenu == '45') {
                                                                
    $tipo_medico '1';
                                                            }
                                                            
    $result=mysql_query($query) or die('Error, seconda query failed');
                                                            
    $row=mysql_fetch_array($resultMYSQL_ASSOC);
                                                            
    $numrows $row['numrows'];
                                                            
    $maxPage ceil($numrows/$rowsPerPage);
                                                            
    // print the link to access each page
                                                            
    $self $_SERVER['PHP_SELF'];
                                                            
    $nav '';
                                                            for(
    $page 1$page <= $maxPage$page++) {
                                                                if (
    $page == $pageNum) {
                                                                    
    $nav .= "<strong><a href='#'>.$page.</a></strong>"// no need to create a link to current page
                                                                
    } else {
                                                                    
    $nav .= " <a href=\"$self?page=$page&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">.$page.</a> ";
                                                                }
                                                            }
                                                            if (
    $pageNum 1) {
                                                                
    $page $pageNum 1;
                                                                
    $prev " <a href=\"$self?page=$page&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">&lt;</a> ";
                                                                
    $first " <a href=\"$self?page=1&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">[First Page]</a> ";
                                                            } else {
                                                                
    $prev  '&nbsp;'// we're on page one, don't print previous link
                                                                
    $first '&nbsp;'// nor the first page link
                                                            
    }
                                                            if (
    $pageNum $maxPage) {
                                                                
    $page $pageNum 1;
                                                                
    $next " <a href=\"$self?page=$page&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">&gt;</a> ";
                                                                
    $last " <a href=\"$self?page=$maxPage&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">[Last Page]</a> ";
                                                            } else {
                                                                
    $next '&nbsp;'// we're on the last page, don't print next link
                                                                
    $last '&nbsp;'// nor the last page link
                                                            
    }
                                                        
    ?>
    l errore è : Error, seconda query failed
    mi potreste dare una mano? grazie a tutti

  2. #2
    dj89, per piacere, fatti stampare le query a video e postale qui: mettersi a leggere quel codice formattato in quel modo è davvero compito arduo!

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2015
    Messaggi
    6
    Codice PHP:
    <?php
    mysql_query
    ("SET CHARACTER SET utf8");
    mysql_query("SET NAMES utf8");
    $rowsPerPage 20;
    $pageNum 1;
    if (isset(
    $_GET['page'])) {
        
    $pageNum $_GET['page'];
    }
    $offset = ($pageNum 1) * $rowsPerPage;
    $lettera=$_REQUEST['lettera'];
    if (
    $lettera == NULL) {
        
    $lettera '';
    } else {
        
    $lettera=$_REQUEST['lettera'];
    }
    if (
    $spec == NULL and $lettera == NULL and $tipo_medico == 1) {
        
    $Sqlqr_gl="select * from medici_chirurghi where cognome != '' order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi where cognome != ''";
    } else if (
    $spec == NULL and $lettera != NULL and $tipo_medico == 1) {
        
    $Sqlqr_gl="select * from medici_chirurghi where cognome != '' and cognome LIKE '$lettera%' order by cognome LIMIT $offset$rowsPerPage";
        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi where cognome != '' and cognome LIKE '$lettera%'";
    } else if (
    $spec != NULL and $tipo_medico == 1) {
        
    $Sqlqr_gl="select m.* from medici_chirurghi m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola";
    } else if (
    $spec == NULL and $lettera == NULL and $tipo_medico == 2) {
        
    $Sqlqr_gl="select * from medici_odontoiatri where cognome != '' order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_odontoiatri where cognome != ''";
    } else if (
    $spec == NULL and $lettera != NULL and $tipo_medico == 2) {
        
    $Sqlqr_gl="select * from medici_odontoiatri where cognome != '' and cognome LIKE '$lettera%' order by cognome  LIMIT $offset$rowsPerPage";
        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_odontoiatri where cognome != '' and cognome LIKE '$lettera%'";
    } else if (
    $spec != NULL  and $tipo_medico == 2) {
        
    $Sqlqr_gl="select m.* from medici_odontoiatri m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola order by IF (ASCII(LOWER(cognome)) >=ASCII (LOWER('$lettera')),1,2),cognome LIMIT $offset$rowsPerPage";
        
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_odontoiatri m, matricola_specialita ms, specialita2 s where cognome != '' and s.id_spec = $spec and s.id_spec = ms.id_specialita and m.matricola2 = ms.matricola";
    }
    echo 
    "<div style=display:none>".$Sqlqr_gl."</div>";
        
    $qr_gl=mysql_query($Sqlqr_gl,$connessione)or die(mysql_error());
        while(
    $r_gl=mysql_fetch_array($qr_gl,MYSQL_ASSOC)) {
        if (
    $r_gl['cognome'] != NULL) {
        
    ?>
    Codice PHP:
    <?php 
    if ($idmenu == '44') {
        
    $tipo_medico '2';
    } else if (
    $idmenu == '45') {
        
    $tipo_medico '1';
    }
    $result=mysql_query($query) or die('Error, seconda query failed');
    $row=mysql_fetch_array($resultMYSQL_ASSOC);
    $numrows $row['numrows'];
    $maxPage ceil($numrows/$rowsPerPage);
    // print the link to access each page
    $self $_SERVER['PHP_SELF'];
    $nav '';
    for(
    $page 1$page <= $maxPage$page++) {
        if (
    $page == $pageNum) {
            
    $nav .= "<strong><a href='#'>.$page.</a></strong>"// no need to create a link to current page
        
    } else {
            
    $nav .= " <a href=\"$self?page=$page&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">.$page.</a> ";
                }
        }
        if (
    $pageNum 1) {
            
    $page $pageNum 1;
            
    $prev " <a href=\"$self?page=$page&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">&lt;</a> ";
            
    $first " <a href=\"$self?page=1&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">[First Page]</a> ";
        } else {
            
    $prev  '&nbsp;'// we're on page one, don't print previous link
            
    $first '&nbsp;'// nor the first page link
        
    }
        if (
    $pageNum $maxPage) {
            
    $page $pageNum 1;
            
    $next " <a href=\"$self?page=$page&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">&gt;</a> ";
            
    $last " <a href=\"$self?page=$maxPage&idmenu=$idmenu&lettera=$lettera&spec=$spec&tipomedico=$tipo_medico\">[Last Page]</a> ";
        } else {
        
    $next '&nbsp;'// we're on the last page, don't print next link
        
    $last '&nbsp;'// nor the last page link
        
    }
        
    ?>

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    Almeno finché sei in fase di sviluppo, nei die() mettici il vero messaggio d'errore con mysql_error(), non metterci un testo scritto da te che non ti descrive niente.

    Altra cosa che puoi fare è che invece di eseguire le query, te le fai stampare a video con un echo, vedi ad occhio se sono generate correttamente, se ti sembrano corrette, copiale e incollale in phpmyadmin per eseguirle a mano, così vedi che ti dice phpmyadmin.

    PS: evita di usare mysql_ usa mysqli_ oppure meglio PDO, tra poco mysql_ non funzionerà più, già su molti hosting non va, man mano che si aggiorneranno anche gli altri mysql_ andrà in pensione e la tua applicazione smetterà di funzionare.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2015
    Messaggi
    6
    l errore è:
    Unknown column 'm.id_albo' in 'field list'

    grazie

  6. #6
    Utente bannato
    Registrato dal
    Jul 2013
    Messaggi
    290
    Penso che il problema sia questo
    codice:
    SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi where
    puoi togliere m., oppure aggiungere una m prima del where
    codice:
    
    
    codice:
    SELECT COUNT(id_albo) AS numrows from medici_chirurghi where
    


    codice:
    
    
    codice:
    SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi m where
    
    Guardando sotto mi pare ci sia stato un copia-incolla di una query dove ci sono dei JOIN e dove le tabelle hanno alias (penso per evitare proprio il problema dello stesso nome ID).

  7. #7
    Utente bannato
    Registrato dal
    Jul 2013
    Messaggi
    290
    Guardando meglio... ma che roba è?
    Ci sono voragini di sicurezza (ehehehehe ormai son diventato un niubbo informato!) ma soprattutto perché tutte quelle manfrine con le lettere?
    Forse (non ho provato troppo lungo) l'order by "strano" impedisce l'utilizzo degli indici durante l'ordinamento.

    Infine toglierei medici_chirurghi e medici_odontoiatri, a favore di un medici (e basta) con un campo "chiurgo" e "odontoiatra" (magari C e O) per dimezzare quel groviglio

  8. #8
    esempio:

    Codice PHP:
    $query="SELECT COUNT(m.id_albo) AS numrows from medici_chirurghi m where cognome != ''";
    //nota: medici_chirurgi m dove "m" è l'alias della tabella da usare per riferirsi alle colonne 
    ti sei scordato, ad esempio in questa query, di mettere l'alias (l'm. che usi nel selezionare le colonne) alla tabella medici_chirurgi. Controlla le altre

    cmq usare due tabelle per distinguere chirurgi e odontoiatri probabilmente era abbastanza inutile. se domani ti servono i pediatri o i generici che fai, aggiungi altre due tabelle? http://blogs.microsoft.co.il/bursteg...-in-databases/
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

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.