dlkinsey85 Posted March 21, 2007 Share Posted March 21, 2007 Hello Everyone, I just stumbled upon your community here and have a question that's been stumping me for several days now. I'm sure the solution is so simple I'm going to be hitting myself because of this. But what I need have a category selected by the user to carry from page to page. I have it working up to the point to where the user moves to another page. For example... say the user is at /example.php and goes to /example.php?pg=2 the category variable is not carrying over and doesn't show anything on page 2 or beyond. Here's what I have so far... $display = 20; $pg = (isset($_REQUEST['pg']) && ctype_digit($_REQUEST['pg'])) ? $_REQUEST['pg'] : 1; $start = $display * $pg - $display; $conn = mysql_connect("localhost", "name", "password"); mysql_select_db("database", $conn); $query = mysql_query("SELECT DISTINCT `category` FROM `table`"); // Start the Form echo "<center> <form method='post' name='categoryForm' action='example.php'>"; $category = !isset($_POST['category'])? NULL : $_POST['category']; echo "<select name='category'> <option value='all'>View All</option>"; // Load Select Menu while ($rowCategory = mysql_fetch_array($query)){ echo "<option value='" . $rowCategory['category'] . "'>" . $rowCategory['category'] . "</option>"; } // end While //End Select Menu echo "</select> <input type='submit' name='submit' value='Go'> </form></center><br><br><br>"; // Determine What the User Wants to See And How Many Pages It Will Be if ($category == "all" || !$category){ $result = mysql_query("SELECT count(*) FROM table"); }else{ $result = mysql_query("SELECT count(*) FROM table WHERE `category` = '$category'"); } // end IF $total = mysql_result($result, 0); if ($category == "all" || !$category){ $product = mysql_query("SELECT * FROM table LIMIT $start, $display"); }else{ $product = mysql_query("SELECT * FROM table WHERE `category` = '$category' LIMIT $start, $display"); } // end IF ELSE // // Page Content // //Determine the Page the User is on if (isset($_SERVER['QUERY_STRING']) && trim($_SERVER['QUERY_STRING']) != '') { if(stristr($_SERVER['QUERY_STRING'], 'pg=')) $query_str = '?'.preg_replace('/pg=\d+/', 'pg=', $_SERVER['QUERY_STRING']); else $query_str = '?'.$_SERVER['QUERY_STRING'].'&pg='; } else $query_str = '?pg='; $pages = ($total <= $display) ? 1 : ceil($total / $display); // Load Navigation $first = '<a href="'.$_SERVER['PHP_SELF'].$query_str.'1">"First"</a>'; $prev = '<a href="'.$_SERVER['PHP_SELF'].$query_str.($pg - 1).'">"Previous";</a>'; $next = '<a href="'.$_SERVER['PHP_SELF'].$query_str.($pg + 1).'">"Next";</a>'; $last = '<a href="'.$_SERVER['PHP_SELF'].$query_str.$pages.'">"Last";</a>'; // Display Navigation if page is > 1 echo '<div><center><br><br>'; echo ($pg > 1) ? "$first : $prev :" : '« : ‹ :'; $begin = $pg - 4; while($begin < 1) $begin++; $end = $pg + 4; while($end > $pages) $end--; for($i=$begin; $i<=$end; $i++) echo ($i == $pg) ? ' ['.$i.'] ' : ' <a href="'. $_SERVER['PHP_SELF'].$query_str.$i.'">'.$i.'</a> '; echo ($pg < $pages) ? ": $next : $last" : ': › : »'; echo '</center></div>'; mysql_close($conn); Any help, ideas, or suggestions would be greatly apprieciated. Link to comment https://forums.phpfreaks.com/topic/43698-global-variable-within-divided-pages/ Share on other sites More sharing options...
dlkinsey85 Posted March 21, 2007 Author Share Posted March 21, 2007 sorry about the bump but I still haven't figured it out Link to comment https://forums.phpfreaks.com/topic/43698-global-variable-within-divided-pages/#findComment-212286 Share on other sites More sharing options...
dlkinsey85 Posted March 21, 2007 Author Share Posted March 21, 2007 another bump... Is anyone willing to try to help? Link to comment https://forums.phpfreaks.com/topic/43698-global-variable-within-divided-pages/#findComment-212419 Share on other sites More sharing options...
kenrbnsn Posted March 22, 2007 Share Posted March 22, 2007 Either put the category on the URL or use sessions. Ken Link to comment https://forums.phpfreaks.com/topic/43698-global-variable-within-divided-pages/#findComment-212453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.