The problem now is that it creates a table like this :
----------------------------------------------------------------------------
| NAME | URL | IMAGE |
----------------------------------------------------------------------------
You can see it here : http://www.planetbabes.net/pagination/index.php
And I want to be like this :
----------------------------------------------------------------------------
| NAME |
----------------------------------------------------------------------------
| IMAGE (The actual image, not the path) |
----------------------------------------------------------------------------
| VIEW GALLERY (url) |
----------------------------------------------------------------------------
Here's the code :
Code: Select all
<?php
//connect to the database
$connect = mysql_connect("localhost", "metallica", "rulez") or
die ("check your server connection.");
// Select the database to use
mysql_select_db ("master_of_puppets") or die (mysql_error());
$limit = 20;
// Sets how many results shown per page
$query_count = "SELECT * FROM galeria ORDER BY ID_Prueba DESC";
// Sets what we want to pull from the database
// count(*) is better for large databases (thanks Greg!)
$result_count = mysql_query($query_count); ;
// Pulls what we want from the database
$totalrows = mysql_num_rows($result_count);
// This counts the number of users
//**********beginning of pagination************
$page = $_GET['page'];
//********check and see what page we're on*********
if(empty($page)){ // Checks if the $page variable is empty (not set)
$page = 1; // If it is empty, we're on page 1
}
$limitvalue = $page * $limit - ($limit);
// Ex: (2 * 25) - 25 = 25 <- data starts at 25
$query = "SELECT * FROM galeria ORDER BY ID_Prueba DESC LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
// Selects all the data from table.
// mysql_error() will print an error if one occurs.
/* Tip: The MySQL LIMIT value syntax is as follows:
LIMIT $row_to_start_at, $how_many_rows_to_return
*/
//***create a table to display data*****
$bgcolor = "#FFFFFF";
/* Sets up one of the background colors. The color stated here will be
displayed second */
echo("<table>");
// Just a simple table
while($row = mysql_fetch_array($result)){
/* This starts the loop (a while loop). What this does is returns a row of data
to the $row array. Each time the loop restarts, the next row of data is used.
So, each pass of the loop returns a different row of data. */
// Start The Background Check
if ($bgcolor == "#FFFFFF"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#FFFFFF";
}
/* Tip: The color you want to appear first on the list should be where the
#FFFFFF is listed. What this script does is checks to see if #E0E0E0 was used
last; if it was, then it'll use #FFFFFF. All you have to do is replace the
colors of your choice. */
echo("<tr bgcolor='.$bgcolor.'><td>");
// Here we start table row & table data
// Make sure your bgcolor is the $bgcolor variable
echo($row["Nombre"]);
//Here we have the name of the recipe field
echo("</td><td>");
// Here we end the one section of table data, and start another.
echo($row["Url"]);
// Prints the author id field
echo("</td><td>");
// Here we end the one section of table data, and start another.
echo("<img src=$row[imagen]>");
// Here we make the link to the full description of the recipe.
echo("</td></tr>");
// Here we end the table data & table row
} /* This closes the loop. Anything after this bracket will display after the
data you've pulled from the database. */
echo("</table>");
/* While we're at it, let's close the table tag--we don't want other data
inside this table */
//****make the previous button********
if ($page != 1){
$pageprev = $page-1;
echo("<a href=\"{$_SERVER['PHP_SELF']}?page=$pageprev\">PREVIOUS"."</a> ");
}else{
echo("PREV");
}
//*****list the page numbers in link format********
$numofpages = $totalrows / $limit;
for ($i = 1; $i <= $numofpages; $i++){
if ($i == $page){
echo($i." ");
}else{
echo("<a href=\"{$_SERVER['PHP_SELF']}?page=$i\">$i</a> ");
}
}
//*****check for remaing rows******
if (($totalrows % $limit) != 0){
if ($i == $page){
echo($i." ");
}else{
echo("<a href=\"{$_SERVER['PHP_SELF']}?page=$i\">$i</a> ");
}
}
//****make the next button*****
if (($totalrows - ($limit * $page)) > 0){
$pagenext = $page+1;
echo("<a href=\"{$_SERVER['PHP_SELF']}?page=$pagenext\"> NEXT"."</a>");
}else{
echo("NEXT");
}
mysql_free_result($result);
?>