2017-05-09 2 views
-3

mysql 데이터베이스에서 많은 항목을 검색하여 html 페이지에 게시하는 방법 PHP에서 새 페이지로 자동으로 이동시켜 사용자가 doesnot이 아닌지 확인하는 방법 html 페이지의 맨 아래까지 스크롤해야합니다.데이터베이스 테이블에서 행을 검색하고 표시 할 때 페이지 매기기를 수행하는 방법

<?php 
$query = "SELECT * FROM venueimage "; 
$result = mysqli_query($connect, $query); 
while($row = mysqli_fetch_array($result)){ 

echo ' 
<div class="container"> 
<div style="border : 2px solid #FDF3E7; background:#ECECEA;"   class="row">'; 
echo' <div class="col-sm-4 border-right">'; 
echo "<u >"; echo "Venue ID :"; echo $row['id'] ; echo "</u>";   echo "</br>"; 

echo "Venue name :"; echo $row['venuename'] ; echo "</br>"; 

echo "Venue address :"; echo $row['address'] ; echo "</br>"; 

echo "Venue phone :"; echo $row['phone'] ; echo "</br>"; 

echo "Venue capacity :"; echo $row['capacity'] ; echo "</br>"; 

echo "prefferedfor :"; echo $row['prefferedfor'] ; echo "</br>"; 

echo "Venue price :"; echo $row['price'] ; echo "</br>"; 

echo "brief description :"; echo $row['briefdescription'] ; echo "  </br>"; 

echo '</div>'; 
echo '<div class="col-sm-8">'; 
echo' 

<img style="width: 790; height: 250" src="data:image/jpeg;base64,'.base64_encode($row['venueimage']).' " /> '; 
    echo '</div>'; 
    echo '</div>'; 
    echo "<hr>"; 
    echo '</div>'; 
    echo "</br>"; 

    } 

    mysqli_close($connect); 
    ?> 
+0

시도를 당신이 달성하려고하는 것을 더 명확하게 설명 할 수 있습니다. –

+0

페이지 매김에 대해 알아보십시오. – Strawberry

+0

내가 원하는 건 SQL select 문을 페이지 당 atleast 5 레코드를 표시하는 것입니다. – matynjr

답변

-1

페이징 (페이지 매김)을 추가하는 솔루션을 구현하려는 것 같습니다. 이것은 일반적인 요구 사항이며 StackOverflow 및 다른 페이지에 많은 솔루션이 존재합니다.

에 체크 아웃은, 당신이 시작할 수 있어야합니다 Simple PHP Pagination script

try { 

// Find out how many items are in the table 
$total = $dbh->query(' 
    SELECT 
     COUNT(*) 
    FROM 
     table 
')->fetchColumn(); 

// How many items to list per page 
$limit = 20; 

// How many pages will there be 
$pages = ceil($total/$limit); 

// What page are we currently on? 
$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
    'options' => array(
     'default' => 1, 
     'min_range' => 1, 
    ), 
))); 

// Calculate the offset for the query 
$offset = ($page - 1) * $limit; 

// Some information to display to the user 
$start = $offset + 1; 
$end = min(($offset + $limit), $total); 

// The "back" link 
$prevlink = ($page > 1) ? '<a href="?page=1" title="First page">&laquo;</a> <a href="?page=' . ($page - 1) . '" title="Previous page">&lsaquo;</a>' : '<span class="disabled">&laquo;</span> <span class="disabled">&lsaquo;</span>'; 

// The "forward" link 
$nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next page">&rsaquo;</a> <a href="?page=' . $pages . '" title="Last page">&raquo;</a>' : '<span class="disabled">&rsaquo;</span> <span class="disabled">&raquo;</span>'; 

// Display the paging information 
echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' of ', $pages, ' pages, displaying ', $start, '-', $end, ' of ', $total, ' results ', $nextlink, ' </p></div>'; 

// Prepare the paged query 
$stmt = $dbh->prepare(' 
    SELECT 
     * 
    FROM 
     table 
    ORDER BY 
     name 
    LIMIT 
     :limit 
    OFFSET 
     :offset 
'); 

// Bind the query params 
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT); 
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT); 
$stmt->execute(); 

// Do we have any results? 
if ($stmt->rowCount() > 0) { 
    // Define how we want to fetch the results 
    $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    $iterator = new IteratorIterator($stmt); 

    // Display the results 
    foreach ($iterator as $row) { 
     echo '<p>', $row['name'], '</p>'; 
    } 

} else { 
    echo '<p>No results could be displayed.</p>'; 
} 

} catch (Exception $e) { 
echo '<p>', $e->getMessage(), '</p>'; 
} 

모든 크레딧을 @Nev 스톡에

+0

다양한 대안을 시도했지만 could not는 nother 솔루션을 가지고있을 수 있습니다. – matynjr

+0

답변이 100 % 다른 스택 응답을 기반으로한다면, 정말 중복으로 폐쇄해야합니다. – xQbert