Jump to content

album numbers


wezze

Recommended Posts

I got a place on my site with pics with numbers beneath the section, what i was wondering is if it is possible when you click number 2

you get the pics of page 2 in place of the existing pics without me needing to make another page in 2 languages everytime.

http://mcbevers.be/leden_nl_p1.phpthis is the page clicking on number 2 wont do anything atm :P

 

any1 got an idea or a link to something i tried google but i dont know how to search this in a couple of words.

 

thx

Link to comment
Share on other sites

You can paginate the results to get what you desire.. 

 

Example:

 

<?php
      // Function to build navigational page links
function generate_pg_links($cur_page, num_pages) {
      $page_links1 = '';
     // If this page is not the first page, generate the previous link
if ($cur_page > 1) {
      $page_links .='<a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . ($cur_page - 1) . '"><-</a> ';
    } else {
      $page_links .= '<- ';
    }

   // Loop through the pages generating the page number links
for ($i = 1; $i <= $num_pages; $i++) {
       if ($cur_page == $i) {
             $page_links .= ' ' . $i;
       } else {
             $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . $i . '"> ' . $i . '</a>';
       }
    }

  // If this page is not the last page, generate the next link
    if ($cur_page < $num_pages) {
         $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' .    ($cur_page + 1) . '">-></a>';
      } else {
      $page_links .= ' ->';
    }

    return $page_links;
    }


// Calculate pagination information
$cur_page = isset($_GET['pg']) ? $_GET['pg'] : 1;
$results_per_page = 5; // Number of results per page
$skip = (($cur_page - 1) * $results_per_page);

// Query that gathers the total number of rows returned
$numrows = "SELECT * FROM sometable";
$result = mysqli_query($dbc, $numrows);
$total = mysqli_num_rows($result);
$num_pages = ceil($total / $results_per_page);

// Query to limit the results
$limitquery = "$pagestuff . " LIMIT $skip, $results_per_page";
$data = mysqli_query($dbc, $query);

// Output the data
while ($row = mysqli_fetch_array($data)) {
  // echo img location here
}

// Generate page links
if ($num_pages > 1) {
      echo '<div id="pg">';
      echo '<p>Page: ' . generate_pg_links($cur_page, $num_pages) . '</p>';
      echo '</div>';
    }
?>

 

I didn't fully test this but if you add your database connection information to the $dbc variable, put the query you need in, and echo out the row for the images like $row['image'] then it should work. But, this is what you seem to need so hope it helps!

Link to comment
Share on other sites

The first portion you have to update with your table that stores the information to the images.

 

 // Query that gathers the total number of rows returned
$numrows = "SELECT * FROM sometable";

 

This is where you will format your output for each picture.. wrap it in a div to contain the content

 

while ($row = mysqli_fetch_array($data)) {
  // echo img location here
}

 

Then you can specify the options here:

// Calculate pagination information
$cur_page = isset($_GET['pg']) ? $_GET['pg'] : 1;
$results_per_page = 5; // Number of results per page
$skip = (($cur_page - 1) * $results_per_page);

 

 

Any clearer now?  ;)

Link to comment
Share on other sites

ok so this is what i got till now1 the php table creation script

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE imglink
(
id unique auto-increment,
linkname varchar(200),
linklocation varchar(200)
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

 

correct?

 

2 the script you gave me with the links you pm me

 

<?php
      // Function to build navigational page links
function generate_pg_links($cur_page, num_pages) {
      $page_links1 = '';
     // If this page is not the first page, generate the previous link
if ($cur_page > 1) {
      $page_links .='<a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . ($cur_page - 1) . '"><-</a> ';
    } else {
      $page_links .= '<- ';
    }

   // Loop through the pages generating the page number links
for ($i = 1; $i <= $num_pages; $i++) {
       if ($cur_page == $i) {
             $page_links .= ' ' . $i;
       } else {
             $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . $i . '"> ' . $i . '</a>';
       }
    }

  // If this page is not the last page, generate the next link
    if ($cur_page < $num_pages) {
         $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' .    ($cur_page + 1) . '">-></a>';
      } else {
      $page_links .= ' ->';
    }

    return $page_links;
    }


// Calculate pagination information
$cur_page = isset($_GET['pg']) ? $_GET['pg'] : 1;
$results_per_page = 5; // Number of results per page
$skip = (($cur_page - 1) * $results_per_page);

// Query that gathers the total number of rows returned
$numrows = "SELECT * FROM imglink";
$result = mysqli_query($dbc, $numrows);
$total = mysqli_num_rows($result);
$num_pages = ceil($total / $results_per_page);

// Query to limit the results
$limitquery = "$pagestuff . " LIMIT $skip, $results_per_page";
$data = mysqli_query($dbc, $query);

// Output the data
while ($row = mysqli_fetch_array($data)) {
  // echo imglocation
}

// Generate page links
if ($num_pages > 1) {
      echo '<div id="pg">';
      echo '<p>Page: ' . generate_pg_links($cur_page, $num_pages) . '</p>';
      echo '</div>';
    }
?>

 

So if this is correct can i make this an include file?

 

thx

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.