I have modified my project into a one page website type.
Part of the code is this:
for ($i = 1; $i <= $total_pages; $i++)
{
echo '<a href="view.php?page='.$i.'" data-role="button">'.$i.'</a>';
}
I need that code above to work with an internal link for example:
From here:
echo '<a href="view.php?page='.$i.'" data-role="button">'.$i.'</a>';
TO
echo '<a href="#my-anchor?page='.$i.'" data-role="button">'.$i.'</a>';
Here is the full source code:
$per_page = 6;
$result = mysql_query("SELECT * FROM mytable ORDER BY date DESC");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
echo '<strong>View Page:</strong> ';
echo '<div data-role="controlgroup" data-type="horizontal">';
for ($i = 1; $i <= $total_pages; $i++)
{
echo '<a href="view.php?page='.$i.'" data-role="button">'.$i.'</a>';
//echo '<a href="#view-pag-events" data-role="button">'.$i.'</a>';
}
echo '</div>';
I need to change this:
echo '<a href="view.php?page='.$i.'" data-role="button">'.$i.'</a>';
so it’s internal.
Short answer: This can’t be done in PHP alone. You will need send AJAX requests to a PHP script that grabs the data.
Basically, this will involve creating some javascript that listens for any changes to the hash (that’s the part after the #);
For AJAX basics, check W3Schools. And please, please respect the back button.