2

So first of let me past my code

<div class="Page_Navigation"><?php 
$sql = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites"; 
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); ?>
<div class="Page_Navigation"><?
echo "<a href='index.php?page=1'>".'<'."</a> "; // Goto 1st page  
for ($i=1; $i<=$total_pages; $i++) { 
    echo "<a href='index.php?page=".$i."'>".$i."</a> "; 
}; 
echo "<a href='index.php?page=$total_pages'>".'>'."</a> "; // Goto last page
?></div>

And here is an image of what it looks like:

And this is what it is supposed to be:

Not only that, but the links are dead:

page=

Machavity
  • 30,841
  • 27
  • 92
  • 100
Ibrahim
  • 23
  • 4

2 Answers2

1

Use mysqli_* or PDO. See the code:-

Try to move your div code before for loop:-

<?php
error_reporting(E_ALL); // check all type of error
ini_set('display_errors',1); // display errors if any
$conn = mysqli_connect('server name','user name','password','database name') or die(mysqli_connect_error); // connect to database

$sql = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites"; 
$rs_result = mysqli_query($sql) or die(mysqli_error($conn)); //run the query
$total_records = mysqli_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); 

echo "<a href='index.php?page=1'>".''."</a>"; // Go to 1st page 
echo '<div class="Page_Navigation">'; 
for ($i=1; $i<=$total_pages; $i++) { 

    echo "<a href=index.php?page=$i>$i</a>";
 }

  echo "<a href=index.php?page=$total_pages></a></div>"; // Go to last page
 ?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
0

Try to move div befor for loop

<?php 
$sql = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites"; 
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); 

echo "<a href='index.php?page=1'>".''."</a>"; // Goto 1st page 
echo '<div class="Page_Navigation">'; 
for ($i=1; $i<=$total_pages; $i++) { 
    echo '<a href="index.php?page='.$i.'">'.$i.'</a> ';
}

echo "<a href='index.php?page=$total_pages'>".''."</a></div> "; // Goto last page
?>

Add to .css file the class:

.Page_Navigation {
   padding: 5px;
   background: #dedede;
   margin: 5px;
}

Or somewhere in the file:

<style>
.Page_Navigation {
   padding: 5px;
   background: #dedede;
   margin: 5px;
}
</style>

I haven't checked if the colors match or the distance, so you need to change that :)

Piotr Pasich
  • 2,639
  • 2
  • 12
  • 14