简单的php分页或用php / mysql进行css分页

I am trying to built a simple php pagination ( a sort of ). or to be more specific css pagination with php/mysql.

Accessing and storing the values from db

 while($row = $result->fetch_assoc()) {
        $id[]=$row["id"];
        $name[]=$row["name"];
        $url[]=$row["url"];
        //echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["url"]. "<br>";
    }

Displaying them

    <ul class="pagination">
        <li><a href="#">«</a></li>
        <?php 
         $i=1;
        for ($x = 0; $x < count($id); $x++) { ?>
        <li>
         <a href=<?php echo "$url[$x]"; ?> target="iframe1"
 title="<?php echo "$name[$x]"; ?>"><?php echo "$i";?></a> 

         </li>
        <?php   $i++;}   ?>


        <li><a href="#">»</a></li>
      </ul>

Once any number shown above is clicked required url is displayed inside iframe1

 <div align="center">
    <iframe name="iframe1" src="http://www.w3schools.com"
 frameborder='0'  height='1000'   width='1000' align="center"></iframe>
    </div>

when I click any number it display the url inside the iframe "iframe1" .

Question:

How do i display first and NEXT {NOT LAST} record in

  <li><a href="#">«</a></li>  [First]
  <li><a href="#">»</a></li>  [Next]

I am looking for a very small code to do the same.

The first link is pretty easy:

<a href=<?php echo "$url[0]"; ?> target="iframe1" 
    title="<?php echo $name[0]"; ?>"><<</a>

For next link It would kind of depend on how your urls are set out. If the $url values are just a name and your url is domain.com/blog?page=page1 where page1 is the value from $url then we get use $_GET['page'] to grab the current page. Then using:

$next = array_search($_GET['page'], $url);

will give us the number in the order of the current page so the next page will simply be $url[$next + 1]

EDIT:

OK if its a url that changes in domain part then the $_GET wont work. You could grab the current url using $_SERVER[REQUEST_URI] and then use the same technique as above to find its position in the array of urls.