0

誰かがこのスクリプトのページ付けを手伝ってくれませんか? 私はそれがあまり得意ではなく、めちゃくちゃにしていました。

私はすでにnum_rowsをチェックしてから検証してみましたが、10回ほど失敗しました:( 2日後にあきらめました。ゼロから始めたいです。

<?php

$link = mysqli_connect("localhost", "lunar_lunar", "", "lunar_users");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$result = mysqli_query($link, "SELECT * FROM users ORDER BY username");
while($row = mysqli_fetch_assoc($result)) {
    $id=$row['id'];
    $username=$row['username'];
    $email=$row['email'];
    $firstname=$row['firstname'];
    $lastname=$row['lastname'];
    $motto=$row['motto'];
    $bio=$row['bio'];
$result4 = mysqli_query($link, "SELECT * FROM photo where id='$id'");
$row4 = mysqli_fetch_assoc($result4);
$image=$row4['filename'];
$src = (empty($image)) ? "upload/your-photo.jpg" : "site_images/$id/$image";
$motto = (empty($motto)) ? "No motto" : $motto;
$bio = (empty($bio)) ? "No biography" : $bio;
echo "<div class='panel panel-default'>
  <div class='panel-heading'>
    <h3 class='panel-title'><a href='public.php?id=".$id."'>".$username."</h3></a>
  </div>
  <div class='panel-body'>
  <div class='gravatar span3' style='padding:0px;margin:0px;'>
  <img src='
    ".$src."' alt='' width='85' height='85'>
    </div>
    <br />
    <div class='page-header'>
  <br />
  </div>
  <p style='margin-right:450px;'>
  ".$bio."
  </p>
  </div>
  <div class='panel-footer'>".$motto."</div>
</div>";
       }
?>
4

1 に答える 1

0

SQL クエリを組み込むには、いくつかの調整を行う必要がありますが、ここには空白のナビゲーション バーがあります (これにより、要求どおりに「正しい方向」に進むことが期待されます)。

<?php

print create_navbar(400, 10);

function create_navbar($count, $items_per_page = 50) {
  // Creates a navigation bar
  $current_page = $_SERVER["PHP_SELF"];
  // You could always pull this next line out and re-add $start_number as the first argument in
  // the function...
  $start_number = ($_GET && isset($_GET['start']) && !empty($_GET['start'])) ? (int) $_GET['start'] : 0;
  if (($start_number < 0) || (! is_numeric($start_number))) {
    $start_number = 0;
  }
  $navbar = "";
  $prev_navbar = "";
  $next_navbar = "";
  if ($count > $items_per_page) {
    $nav_count = 0;
    $page_count = 1;
    $nav_passed = false;
    while ($nav_count < $count) {
    // Are we at the current page position?
      if (($start_number <= $nav_count) && ($nav_passed != true)) {
        $navbar .= '<b><a href="' . $current_page . '?start=' . $nav_count . '">[' . $page_count . '] </a></b>';
        $nav_passed = true;
        // Do we need a "prev" button?
        if ($start_number != 0) {
          $prevnumber = $nav_count - $items_per_page;
          if ($prevnumber < 1) {
            $prevnumber = 0;
          }
          $prev_navbar = '<a href="' . $current_page . '?start=' . $prevnumber . '"> &lt;&lt;Prev - </a>';
        }
        $nextnumber = $items_per_page + $nav_count;
        // Do we need a "next" button?
        if ($nextnumber < $count) {
          $next_navbar = '<a href="' . $current_page . '?start=' . $nextnumber . '"> - Next&gt;&gt; </a><br>';
        }
      }
      else {
        // Print normally.
        $navbar .= '<a href="' . $current_page . '?start=' . $nav_count . '">[' . $page_count . '] </a>';
      }
      $nav_count += $items_per_page;
      $page_count++;
    }
    $navbar = $prev_navbar . $navbar . $next_navbar;
    return $navbar;
  }
}
?>
于 2013-10-13T03:22:45.413 に答える