简体   繁体   English

php pdo分页与FULL JOIN连续结果

[英]Php pdo pagination with FULL JOIN continuous result

i dont know what is wrong with this code but if i use FULL JOIN the pagination continuous on the JOINed table. 我不知道这段代码有什么问题,但是如果我使用FULL JOIN在JOINed表上连续进行分页。 I mean if the JOINed table have more rows than first table, the result is empty html table but with many pages. 我的意思是,如果JOINed表的行数比第一个表多,则结果是空的html表,但页面很多。 If i remove the JOINed table the result is normal table with 5-6 rows. 如果我删除JOINed表,则结果是5-6行的普通表。 But when JOIN and the table become with 5-6 rows with info and 100 with empty cells. 但是当JOIN和表格变成5-6行时包含info,而100行时包含空单元格。 Any advices for this code? 此代码有什么建议吗? Or i have to use other code? 还是我必须使用其他代码? I cant beleive that pagination is such a pain, cant find good working code. 我不能相信分页是一种痛苦,找不到良好的工作代码。 Thank you in advance! 先感谢您! Here is the trouble code: 这是故障代码:

{
/* Set the number of results to display on each page. */
$rowsPerPage = 20;

try
{
    //$query = 'SELECT COUNT(*) FROM paerp.dbo.Truck';
    // simple query
    //$stmtcount = $pdo->query( $query );
    //$rowcountall = $stmtcount;
/* Order target data by ID and select only items (by row number) to display        on a given page. 
   The query asks for one "extra" row as an indicator that another page of    data exists. */
$tsql = "SELECT * FROM 
            (SELECT  ROW_NUMBER() OVER(ORDER BY d.id desc) 
            AS RowNumber, d.id as iddr, d.SqlInsertDate, d.PACourceNumber,    d.ClientQuerydate, d.ClientName, d.SpeditorName, d.CourseType, d.Driver1, d.Driver2, d.TruckRegisteredNumber,          d.TrailerRegisteredNumber, d.StartWorkingDay, d.LoadingAddress, d.UnloadingAddress, d.AgreedLoadingDay, d.ArrivalLoadingDay, d.DateTimeLoading, d.AgreedUnloadingDay, d.ArrivalUnloadingDay, d.DateTimeUnloading, d.PossitionAt8, d.PossitionAt15, d.NextLoading, d.PossitionNumber, d.ExportImport, d.LoadingCustoms, d.UnloadingCustoms, d.InvoiceNumber, d.StatusCource, d.StatusTruck, d.Notes, e.id, e.Names 
FROM dbo.ClientQueries d
FULL JOIN dbo.Employee e ON d.Driver1 = e.id )
        AS TEST 
        WHERE RowNumber BETWEEN ? AND ? + 1";

$sth = $pdo->prepare($tsql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));

/* Determine which row numbers to display. */
if(isset($_GET['lowRowNum']) && isset($_GET['highRowNum']))
{
    $lowRowNum = $_GET['lowRowNum'];
    $highRowNum = $_GET['highRowNum'];
}
else
{
    $lowRowNum = 1;
    $highRowNum = $rowsPerPage;
}

/* Execute the query with parameter values. */
$sth->execute(array($lowRowNum, $highRowNum));

$numRows = $sth->rowCount(); 

if($numRows <= 0) 
{ 
    echo "No data returned.</br>"; 
} 
else 
{ 

 echo '<h3>Преглед записи </h3>';
    print("<table class='mytable'>
           <tr class='headertb'>

        <td class='bold'>SqlInsertDate</td>
           <td class='bold'>PACourceNumber</td>
           <td class='bold'>ClientQuerydate</td>
           <td class='bold'>ClientName</td>
           <td class='bold'>SpeditorName</td>
           <td class='bold'>CourseType</td>
           <td class='bold'>Driver</td>
           <td class='bold'>Driver2</td>
           <td class='bold'>TruckRegisteredNumber</td>
           <td class='bold'>TrailerRegisteredNumber</td>
           <td class='bold'>StartWorkingDay</td>
           <td class='bold'>LoadingAddress</td>
           <td class='bold'>UnloadingAddress</td>
           <td class='bold'>AgreedLoadingDay</td>
           <td class='bold'>DateTimeLoading</td>
           <td class='bold'>DateTimeUnloading</td>
           <td class='bold'>PossitionAt8</td>
           <td class='bold'>PossitionAt15</td>
           <td class='bold'>PossitionNumber</td>
           <td class='bold'>StatusCource</td>
           <td class='bold'>StatusTruck</td>
           <td class='bold'>Notes</td>             
            <td class='bold'>Редакция</td>
            </tr>");

    /*Display all but the last of the rows in the result set.*/ 
    for($i=0; $i<$numRows-1; $i++) 
    { 
        $row = $sth->fetch(PDO::FETCH_NUM); 
        print("<tr>
            <td>$row[1]</td>
            <td>$row[2]</td>
            <td>$row[3]</td>
            <td>$row[4]</td>
            <td>$row[5]</td>
            <td>$row[6]</td>
            <td>$row[7]</td>
            <td>$row[8]</td>
            <td>$row[9]</td>
            <td>$row[10]</td>
            <td>$row[11]</td>
            <td>$row[12]</td>
            <td>$row[13]</td>
            <td>$row[14]</td>
            <td>$row[15]</td>
            <td>$row[16]</td>
            <td>$row[17]</td>
            <td>$row[18]</td>
            <td>$row[19]</td>
            <td>$row[20]</td>
            <td>$row[21]</td>
            <td>$row[22]</td>
            <td>$row[23]</td>
            <td>$row[24]</td>
            <td>$row[25]</td>
            <td><a href=update.php?id=$row[1]>Редакция</a></td></tr>"); 
    } 
    /*Display the last row in the result set if 
      there isn't another page of results.*/ 
    if($numRows <=20) 
    { 
        $row = $sth->fetch(PDO::FETCH_NUM); 
        print("<tr>
            <td>$row[1]</td>
            <td>$row[2]</td>
            <td>$row[3]</td>
            <td>$row[4]</td>
            <td>$row[5]</td>
            <td>$row[6]</td>
            <td>$row[7]</td>
            <td>$row[8]</td>
            <td>$row[9]</td>
            <td>$row[10]</td>
            <td>$row[11]</td>
            <td>$row[12]</td>
            <td>$row[13]</td>
            <td>$row[14]</td>
            <td>$row[15]</td>
            <td>$row[16]</td>
            <td>$row[17]</td>
            <td>$row[18]</td>
            <td>$row[19]</td>
            <td>$row[20]</td>
            <td>$row[21]</td>
            <td>$row[22]</td>
            <td>$row[23]</td>
            <td>$row[24]</td>
            <td>$row[25]</td>
            <td><a href=update.php?id=$row[1]>Редакция</a></td>
            </tr>"); 
    } 

    print("</table></br></br>"); 
    /* If there are previous results, 
        display the Previous Page link. */ 
    if($lowRowNum > 1) 
    { 
        $prev_page_high = $lowRowNum - 1; 
        $prev_page_low = $prev_page_high - $rowsPerPage + 1; 
        $prevPage = "?lowRowNum=$prev_page_low&".
                     "highRowNum=$prev_page_high"; 
        print("<a href=$prevPage><< Предишна страница</a>".
               "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"); 
    } 
    /* If there are more results, display the Next Page link.   
       We know there are more results if the query returned 11 rows. */ 
    if($numRows >= 21) 
    {        
        $next_page_low = $highRowNum + 1; 
        $next_page_high = $next_page_low + $rowsPerPage - 1; 
        $nextPage = "?lowRowNum=$next_page_low&".
                     "highRowNum=$next_page_high"; 
        print("<a href=$nextPage>Следваща страница >></a>"); 
    } 
}
 }
catch(Exception $e)
 { 
die( print_r( $e->getMessage() ) ); 
 }
}

A friend give me the answer to me. 一个朋友给我答案。 So the answer is in the JOIN clause, it should be INNER JOIN not FULL JOIN . 所以答案在JOIN子句中,应该是INNER JOIN而不是FULL JOIN And instead of this $row = $sth->fetch(PDO::FETCH_NUM); 而不是这个$row = $sth->fetch(PDO::FETCH_NUM); have to change to this $row = $sth->fetch(PDO::FETCH_LAZY); 必须更改为$row = $sth->fetch(PDO::FETCH_LAZY); and have to use named parameters where i need. 并在需要的地方使用命名参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM