Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the ids are numeric, this is very easy. Assuming the URL for displaying a project is:</p> <pre>http://myserver/project.php?id=3</pre> <p>...you just need to do something like:</p> <p> <pre><code> // Sanitise user input $currentId = (int) $_GET['id']; // Calculate next/prev IDs $nextId = $currentId + 1; $prevId = ($currentId &gt; 1) ? $currentId - 1 : 1; // Make sure the previous ID is not below 1 // Make links $nextLink = "&lt;a href=\"project.php?id=$nextId\"&gt;Next&lt;/a&gt;"; $prevLink = "&lt;a href=\"project.php?id=$prevId\"&gt;Previous&lt;/a&gt;"; </code></pre> <p>If you are doing it based on the file names themselves, it's a little more tricky - but only a little. You would need to get a list of files in the directory, and use them instead. Now we'll assume your URL's look like:</p> <pre>http://myserver/project.php?name=somefile</pre> <pre><code>&lt;?php // Sanitise user input $currentFile = basename($_GET['name']); // These will hold the previous/next project names $prev = $next = ''; // Loop the directory until we find the current file $dp = opendir('.'); // Open current dir, this can be adjusted to your file structure while (($file = readdir($dp)) !== FALSE) { if (in_array($file, array('.','..')) continue; // Skip . and .. if ($file == $currentFile) { if (($file = readdir($dp)) !== FALSE) { $next = $file; } break; } $prev = $file; } closedir($dp); // Make links if ($next !== '') { $nextLink = '&lt;a href="project.php?name='.htmlspecialchars($next).'"&gt;Next&lt;/a&gt;'; } else { // Handle no next project here } if ($prev !== '') { $prevLink = '&lt;a href="project.php?name='.htmlspecialchars($prev).'"&gt;Previous&lt;/a&gt;'; } else { // Handle no previous project here } </code></pre>
 

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