Jump to content

Problem with OpenCart and Pagination


Bravat

Recommended Posts

I had to create a custom search for OpenCart (with multiple drop down lists), and now i need to create a custom pagination. Code is working fine until i click next or page number, then I get errors (it is the same like when you go directly to search page without submitting search query (Undefined index: Rim in... and it list all the indexes)).

 

This is part of the drop down lists:

<form id="form1" name="form1" method="post" action="index.php?route=product/search"> 


            <input type="text" value="keyword" id="filter_keyword" name="keywords" onclick="this.value = '';" onkeydown="this.style.color = '000000'" style="color: #999;width:154px;">
  

            <?php
            $result = mysql_query("SELECT *
FROM product
GROUP BY Rim");
            ?>
            
  <select id="Rim" name="Rim"  selected="selected" style="width:158px;position:static;z-index:-1;">
  <option value="rim" selected="selected"><?php echo "Rim"; ?></option>

<?php

while ($row = mysql_fetch_array($result)) {
  echo "<option>" . $row['Rim']  . "</option>";
  echo "<br />";
  } ?>
  
       </select> 
.....
<input type="submit" name="Kreni"  value="Pretrazi" />

 

and this is  pagination part (where search is routed):

$per_page = 4;
   if(isset($_POST['Pretrazi'])){
   $start = $_POST['start'];}
       
    $result = mysql_query($query) or die("Couldn't execute query");
    $record_count = mysql_num_rows($result);
    
    $max_pages = $record_count / $per_page;
    
        		$start = 0;
    
    
    $query .= "LIMIT $start, $per_page";
    $result = mysql_query($query);
    
    echo "<p>You searched for: <br> "" . $rimp . " " . $dimenzijap . $sezona . " "</p><hr>";
if($result && mysql_num_rows($result) > 0)
{
    $i = 0;
    $max_columns = 4; ?><table class="tabela"><?php
    while($row = mysql_fetch_assoc($result))        
   {    $title = $row["Rim"];  
        $model = $row["model"];
        $dimenzija = $row["Dimenzija"];
        $ime = $row['name'];
        $cena = $row['price']; 
        $cena = number_format($cena, 2, ',', '.');
        $id = $row['product_id'];
                   
   if($i == 0)
          echo "<tr>";
          echo "<td>" ?><a href="index.php?route=product/product&product_id=<?php echo $id?>"><?php echo $model ?></a>
          <?php echo "<br>$dimenzija<br>$ime<br>"; ?>
          <span style="color: #900; font-weight: bold;"><?php echo $cena . "din"?> </span>
          <?php echo "</td>";
           if(++$i == $max_columns) 
       {
           echo "</tr>";
           $i=0;
       } }}
       if($i > 0)
{
   for($j=$i; $j<$max_columns;$j++) echo "<td> </td>";
   echo "</tr>";
}
?>
</table>
<?php 
$prev = $start - $per_page;
$next = $start + $per_page;

?>
<table width="100%" border="1">
<tr><td><?php 
if (!($start<=0)){
echo "<a href='index.php?route=product/search&start=$prev'>Prev </a>";
}
$page = 1;
for($x=0;$x<$record_count;$x=$x+$per_page){
 	echo " <a href='index.php?route=product/search&start=$x'> $page </a> ";
	$page++;
 }

  if (!($start>=$record_count - $per_page)){
echo "<a href='index.php?route=product/search&start=$next'> Next</a>";
}
?></td>
</tr>
</table>

What seems to be the problem?

 

Link to comment
Share on other sites

  • 2 months later...
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.