0

in the following code , i am trying to display 10 products detail on one page and then other products detail on next page. the problem is when i am clicking the page 2 link in the bottom , it gives error message that " please select the category". please help me where is the problem in my code.

 $SQLstring = "SELECT product_id FROM products LIMIT $offset,$rowsperpage";    
echo "<table border='1' width=500 ><tr><th>Product ID</th>tr>"; 

    while ($Row = mysqli_fetch_assoc($QueryResult))
             {
              $productid = $Row['product_id'];
         echo "<tr><td>$productid</td></tr>";
 }

    echo "</table>"; 
    $range = 3;
   if ($currentpage > 1)
     {  
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";   
    $prevpage = $currentpage - 1;   
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } 
  for ($x = ($currentpage - $range);$x < (($currentpage + $range) + 1); $x++) 
    {   
     if (($x > 0) && ($x <= $totalpages)) 
    {
    if ($x == $currentpage) 
   {
   echo " [<b>$x</b>] ";  
   } 
   else 
    {     
  echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";      
     }}}                

    mysqli_close($DBConnect);
}

3 Answers 3

2

Your Problem is this:

$category=$_POST["categor"];

After someone clicked on the link, $_POST["categor"] will be empty. Try $_REQUEST["categor"] and create the links like this:

echo " <a href='{$_SERVER['PHP_SELF']}?category=".$category."&currentpage=1'><<</a> "; 

or

echo " <a href='{$_SERVER['PHP_SELF']}?category=".$category."&currentpage=$prevpage'><</a> ";

Doing this you can use POST and GET.

Sign up to request clarification or add additional context in comments.

3 Comments

Perhaps you have some equal problems with them, would you show us some Code?
Tokk i have added my html and javascript code, problem is that 'update' and 'delete' buttons are not working now for each product. also next page products detail are displaying in white page.not like the first page (formatted).
Your JS funktion does not match it's call => updateproduct(dataSource,divID,categ) vs onClick='updatethisitem(\"$productid\");. First the name is different and furthermore are the parameters mismatching
1

I think I see the problem...

It doesn't look like you are passing the category into your next page, maybe store the $_POST['categor'] as a session variable, and then check against that instead of a $_POST.

Alternatively, append the category as well as the next page number to the url

$cat = isset($_REQUEST['categor']) ? $_REQUEST['categor'] : "none";

if ($currentpage != $totalpages) {   
    $nextpage = $currentpage + 1;    
    echo " <a href='{$_SERVER['PHP_SELF']}?cat=$cat&currentpage=$nextpage'>></a> ";  
    echo " <a href='{$_SERVER['PHP_SELF']}?cat=$cat&currentpage=$totalpages'>>></a> ";
}

Comments

1

Your generated links don't include the category. So in all your links make sure to include categor=$category like this:

echo " <a href='{$_SERVER['PHP_SELF']}?categor=$category&currentpage=...

EDIT: Then, as others correctly caught, you need to change $_POST to $_REQUEST which I've changed in your code example.

Hope that helps.

5 Comments

furthermore he needs to change $_POST to $_REQUEST
Had to downvote you because it seemed you didn't read the $_POST
You're right. Need to be $_REQUEST in order to get the variable. I've edited.
I think it is very bad to change the questioners code to match your answer! Edit your answer not the question!
Point taken. Just trying to help them see it in context, but you're right, that would seem to bias the question in favor of a given answer. Thanks for the healthy discussion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.