I think my code is sloppy can anyone give me advice to do it better?
This is a page pagination that get rows from mysql db and calculate the number of pages.
<div class="row">
<div class="twelve columns tac">
<?php
//Check for the current page and select one of the two versions of "back" link.
if (isset($_GET["page_num"]) && $_GET["page_num"] >= 2): ?>
<a href="?page=blog&page_num=<?php echo($_GET["page_num"] - 1); ?>">Back</a>
<?php else : ?>
<span>Back</span>
<?php endif;
//looping through the number of pages and list page numbers.
for ($i = 1; $i <= $totalPages; $i++): ?>
<?php if ($i == $_GET["page_num"]) : ?>
<span><?php echo $i; ?></span>
<?php else : ?>
<a href="?page=blog&page_num=<?php echo $i; ?>"> <?php echo $i; ?></a>
<?php endif; ?>
<?php endfor;
//Check for the current page and select one of the two versions of "Next" link.
if ($_GET["page_num"] < $totalPages): ?>
<a href="?page=blog&page_num=<?php echo($_GET["page_num"] + 1); ?>">Next</a>
<?php else : ?>
<span>Next</span>
<?php endif; ?>
</div>
</div>