Visualizzazione dei risultati da 1 a 5 su 5

Visualizzazione discussione

  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2012
    residenza
    Bologna
    Messaggi
    38

    Problema con query, ordinamento e limit

    Ciao a tutti!
    Sto utilizzando uno script trovato in rete per la paginazione di risultati in ajax e php; tutto funziona perfettamente tranne che non riesco a visualizzare in modo corretto i dati prelevati dal database.

    L'errore sta sicuramente nell'ordinamento della query che preleva i dati, ma non capisco come modificarla:

    Codice PHP:
      if($_POST['page'])
    {
    $page = $_POST['page'];
    $cur_page = $page;
    $page -= 1;
    $per_page = 5;
    $previous_btn = true;
    $next_btn = true;
    $first_btn = true;
    $last_btn = true;
    $start = $page * $per_page;

    mysql_select_db($database_config, $config);
    $query_datascored = "SELECT f_matchevents.eplayer_id, sum(ecount) as count, f_player.playerName, f_player.playerID  FROM f_matchevents, f_player WHERE f_matchevents.eplayer_id = f_player.id AND f_matchevents.dt_id = ($tournamentID) AND  f_matchevents.eautogol=0 GROUP BY f_matchevents.eplayer_id ORDER BY count DESC LIMIT $start, $per_page";
    $datascored = mysql_query($query_datascored, $config) or die(mysql_error());
    $row_datascored = mysql_fetch_assoc($datascored); 

    $msg = "";?>

    <?php while ($row_datascored mysql_fetch_assoc($datascored)) { 
          
            
    $msg .= '<tr class="on">
         <td class="value">'
    .$row_datascored['count'].'</td>
         <td class="l_player"><a href="http://sofifa.com/player/'
    .$row_datascored['playerID'].'" target="_new">'
          
    .$row_datascored['playerName'].
           
    '</a></td>
         <td class="r_club">
         <a href="playerscore.php?recordID='
    .$row_datascored['eplayer_id'].'&recordID2='$tournamentID.'"><img src="images/stats.png" width="18" height="18" alt="Dettagli" /></a>
         </td>
         </tr>'    
        
    ;} ?>
          
    <?php     $msg "<table class='sortTable'><div class='data'><ul>" $msg "</ul></div></table>";?>

            
    <?php mysql_select_db($database_config$config);
    $query_countdatascored sprintf("SELECT f_matchevents.eplayer_id, sum(ecount) as count, f_player.playerName, f_player.playerID  FROM f_matchevents, f_player WHERE f_matchevents.eplayer_id = f_player.id AND f_matchevents.dt_id = ($tournamentID) AND  f_matchevents.eautogol=0 GROUP BY f_matchevents.eplayer_id");
    $countdatascored mysql_query($query_countdatascored$config) or die(mysql_error());
    $row_countdatascored mysql_fetch_assoc($countdatascored);
    $totalRows_countdatascored mysql_num_rows($countdatascored);

    $no_of_paginations ceil($totalRows_countdatascored $per_page);

    /* ---------------Calculating the starting and endign values for the loop----------------------------------- */
    if ($cur_page >= 7) {
        
    $start_loop $cur_page 3;
        if (
    $no_of_paginations $cur_page 3)
            
    $end_loop $cur_page 3;
        else if (
    $cur_page <= $no_of_paginations && $cur_page $no_of_paginations 6) {
            
    $start_loop $no_of_paginations 6;
            
    $end_loop $no_of_paginations;
        } else {
            
    $end_loop $no_of_paginations;
        }
    } else {
        
    $start_loop 1;
        if (
    $no_of_paginations 7)
            
    $end_loop 7;
        else
            
    $end_loop $no_of_paginations;
    }
    /* ----------------------------------------------------------------------------------------------------------- */
    $msg .= "<div class='pagination'><ul>";

    // ENABLE THE PREVIOUS BUTTON
    if ($previous_btn && $cur_page 1) {
        
    $pre $cur_page 1;
        
    $msg .= "<li p='$pre' class='active'><img src='images/Previous.gif' width='15' height='15' /></li>";
    } else if (
    $previous_btn) {
        
    $msg .= "<li class='inactive'><img src='images/Previous.gif' width='15' height='15' /></li>";
    }

    // ENABLE THE NEXT BUTTON
    if ($next_btn && $cur_page $no_of_paginations) {
        
    $nex $cur_page 1;
        
    $msg .= "<li p='$nex' class='active'><img src='images/Next.gif' width='15' height='15' /></li>";
    } else if (
    $next_btn) {
        
    $msg .= "<li class='inactive'><img src='images/Previous.gif' width='15' height='15' /></li>";
    }

    echo 
    $msg;
    }
    In questo caso dovrebbero essere visualizzati 5 risultati per ogni pagina, ma in pratica il primo record di ogni pagina viene saltato. Questo succede nonostante la variabile $start, posizionata dopo il LIMIT all'interno della query, abbia valore 0.

    Perchè?
    Ultima modifica di botmite; 17-06-2014 a 14:47

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.