Use pagination in 2 lists without one influencing the other

1

I am listing images and characteristics of them that are collected from the database. As can be seen below, I'm already listing the 2 images and their characteristics, each image is from a table in the database.

The problem I am having is that when I click to go to the next photo of "INOX BAFO BARREL" the "INOX BARREL" also changes.

Paging code:

$nr = mysql_num_rows($sql);

if (isset($_GET['pn'])) { 
$pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); 

} else { 
$pn = 1;
} 

$itemsPerPage = 1; 

$lastPage = ceil($nr / $itemsPerPage);


if ($pn < 1) { 
$pn = 1; 
} else if ($pn > $lastPage) { 
$pn = $lastPage; 
} 

$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
}
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 

$sql2 = mysql_query("SELECT * FROM churrasqueira_bafo ORDER BY id ASC $limit"); 

$paginationDisplay = "";

if ($lastPage != "1"){

    $paginationDisplay .= '';

    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"><i class="icon-arrow-left"></i></a> ';
    } 

    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"><i class="icon-arrow-right"></i></a> ';
    } 
}

This code is to display the list of "BAFO" grills. Then I tried to change the code only by changing the variable of pagination , which to show the practice barbecue is paginationDisplay2 .

    
asked by anonymous 06.03.2014 / 21:12

1 answer

1

From what you can understand in your question, you are using the same code for both pages, but you are not telling which list the user clicked to request to change the image and associated characteristics.

Without seeing all your code it's hard to be assertive enough to present you with a working solution, but in theory, what you need to do is add a parameter to each link that identifies the list and another that identifies the record which is being presented.

With these parameters you will be able to know which of the lists to change on the PHP side and which one should stay as it was.

Example

Taking the links from your current page we add the following to the address:

  • URL parameter s with value 1 or 2 to identify sliders;
  • URL parameter a with the previous field ID so that we can display the record that was being displayed in the slider that was not "clicked."

Illustration of new URL with slider indication s and previous record indication a :

<!--                                  slider à esquerda      registo com ID 15            -->
<!--                                                 ↓        ↓                           -->
<a href="'.$_SERVER['PHP_SELF'].'?pn='.$add1.'&amp;s=1&amp;a=15"> </a>

On the PHP side we will check the clicked slider and for the slider not clicked let's see which register was being presented:

Example code for slider pagination # 1

// Se temos a variável de URL "s" e a mesma é o número 1
if (isset($_GET['s']) && is_numeric($_GET['s']) && $_GET['s']==1) {

  /* ir à base de dados recolher o
   * registo conforme estavas a fazer
   */


// se a variável de URL "s" não é 1, então é porque o utilizador
// clicou na paginação do slider #2 e para este slider devemos
// apresentar novamente o registo anterior que vem identificado
// na variável de URL "a"
} elseif (isset($_GET['a']) && is_numeric($_GET['a'])) {

  $apresentarRegistoComID = $_GET['a'];
  // consultar a base de dados para recolher o registo com o ID = "$apresentarRegistoComID"
}

For slider # 2, it is copy & paste , where it only changes the slider number from 1 to 2 .

    
06.03.2014 / 22:10