Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Pagination Link Generation
    primarykey
    data
    text
    <p>I have this script below which i found on SO to generate pagination and broadly speaking, its working great, however because its a cut and paste job from me, i don't understand how to actually generate the links which are echoed in the script with the variable $pagination.</p> <p>What it echos is:</p> <pre><code>1&lt; a href="index.php?page=2"&gt;2&lt; a href="index.php?page=3"&gt;3&lt; a hr_ef="?page=2"&gt; Next </code></pre> <p>None of which are working (clickable) links, and i also want to be able to style them so would rather output them in HTML, rather than a php echo, something like:</p> <pre><code>&lt;p&gt;&lt;?php 1&lt; a href="index.php?page=2"&gt;2&lt; a href="index.php?page=3"&gt;3&lt; a hr_ef="?page=2"&gt; Next ?&gt; &lt;/p&gt; </code></pre> <p>Below is the script i'm using:</p> <pre><code>&lt;?php /* Set current, prev and next page */ $page = (!isset($_GET['page']))? 1 : $_GET['page']; $prev = ($page - 1); $next = ($page + 1); /* Max results per page */ $max_results = 10; /* Calculate the offset */ $from = (($page * $max_results) - $max_results); /* Query the db for total results.*/ $result = mysql_query("..."); $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $max_results); $pagination = ''; /* Create a PREV link if there is one */ if($page &gt; 1) { $pagination .= '&lt; a href="?page='.$prev.'"&gt;Previous&lt;/a&gt; '; } /* Loop through the total pages */ for($i = 1; $i &lt;= $total_pages; $i++) { if(($page) == $i) { $pagination .= $i; } else { $pagination .= '&lt; a href="index.php?page='.$i.'"&gt;'.$i.'&lt;/a&gt;'; } } /* Print NEXT link if there is one */ if($page &lt; $total_pages) { $pagination .= '&lt; a hr_ef="?page='.$next.'"&gt; Next&lt;/a&gt;'; } /* Below is how you query the db for ONLY the results for the current page */ $query ="SELECT * FROM ... LIMIT $from, $max_results"; $result=mysql_query($query) or die(mysql_error()); $rsjobinfo=mysql_fetch_assoc($result); do {?&gt; &lt;div&gt; [Individual Row Output] &lt;/div&gt; &lt;?php } while ($rsjobinfo=mysql_fetch_assoc($result)); echo $pagination; ?&gt; </code></pre> <p>Can someone help? I imagine its a small fix but as always, would appreciate a kick in the right direction.</p> <p>Thanks Dan</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload