2017-05-09 7 views
-3

mysqlデータベースから多くのアイテムを取得してHTMLページに投稿する方法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

私が望むのは、ページごとに5つ以上のレコードを表示するSQL SELECT文です – 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

私はいろいろな選択肢を試しましたが、うまくいきませんでした – matynjr

+0

回答が100%重複して閉じる必要があります。 – xQbert

関連する問題