millercepbs Posted May 25, 2006 Share Posted May 25, 2006 It's amazing the discoveries you make when you add large amounts of data to something you've tested already. "It used to work, and now it doesn't".I have a query that uses the value from a combo box to make a list...ie the user selects a department from the combo box and gets all items located in that department. I list 25 items per page, but when i go to my next page, I lose all my data and my combo box resets itself to the default value. I can still scroll through the pages of blank, but that's not real helpful.I was thinking that maybe a session variable would work for this, but I'm new to it all so I'm not sure if I'm looking at the wrong kind of solution. Plus I'm not sure that my implementation of _session was correct.Here's how I have it set now:$currentPage = $_SERVER["PHP_SELF"];$selectedDepartment = $_POST['cmbSelect'];and my query just uses the variable as part of a conditional:WHERE inv_inventory.departmentID = '$selectedDepartment'Any guidance would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/10437-retain-combp-value-for-query/ Share on other sites More sharing options...
eves Posted May 26, 2006 Share Posted May 26, 2006 you might want to check for the following:1. FORM method is POST and not GET2. select box is named "cmbSelect" (I know, but just in case ;])3. say you have this links to move to the next page: Page 1 2 3 4 ..... do you link them as <a href='<?echo $_SERVER["PHP_SELF"]."?page=$ctr"?>'> if yes, then your passing your next page in a query string, so test for it using GETsomething like[code]$selectedDepartment = 1; // default valueif ($_SERVER['REQUEST_METHOD']=='POST' && isset($_POST['cmbSelect'])){ $selectedDepartment = intval($_POST['cmbSelect']);}elseif ($_SERVER['REQUEST_METHOD']=='GET' && isset($_GET['page'])){ $selectedDepartment = intval($_GET['page']);}if ($selectedDepartment ==0) $selectedDepartment = 1; //just in case something went wrong above[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10437-retain-combp-value-for-query/#findComment-39068 Share on other sites More sharing options...
millercepbs Posted May 26, 2006 Author Share Posted May 26, 2006 Thanks so much for helping! That does exactlly what I was trying to do. But something I didn't expect happens now. The combo box value still resets to default. I thought I could just use <?php echp $_POST['cmbSelect']; ?> but that killed the page and using $selectedDepartment is what reverts it to the default value. It's not a huge deal, but it could be confusing if you don't remember what item you had done the search on...say I searched in Billing, but when I got to page 4 of the Billing Department, it would have been reset to Accounting...so mindgames so say the least. Your help would be MUCH appreciated again.THANKS!A little premature happiness I'm afraid. When I went and check it, the value in the combo box changing alters the results of the query. So if I search for a department, then the values do query corerectly, but if I move to the next page, the combo box resets. Now if I go back to page one, the values displayed are for that default combo value instead of what I serached for. Quote Link to comment https://forums.phpfreaks.com/topic/10437-retain-combp-value-for-query/#findComment-39200 Share on other sites More sharing options...
eves Posted May 27, 2006 Share Posted May 27, 2006 do this to your select box[code]<select name='cmbSelect'><?php $sel_options = "";$result = mysql_query("SELECT dept_id, department FROM tbl_departments ORDER BY department ASC ");while ($row = mysql_fetch_assoc($result)){ $selected = ""; if ($dept_ds[$ctr]==$selectedDepartment) $selected = " selected "; $sel_options .= "<option value='".$row['dept_id']."' $selected>".$row['department']."</option>"; }echo $sel_options;?></select>[/code]just made up the fields on the SQL above, what it does is it selects the previously chosen department Quote Link to comment https://forums.phpfreaks.com/topic/10437-retain-combp-value-for-query/#findComment-39396 Share on other sites More sharing options...
millercepbs Posted May 30, 2006 Author Share Posted May 30, 2006 Here's what I have right now. Maybe you could guide me from that code?[code]<select name="cmbSelect" id="cmbSelect"><?php do{ ?><option value="<?php echo $row_rsCategory['categoryID']?>"<?php if (!(strcmp($row_rsCategory['categoryID'], "$selectedCategory"))) {echo "SELECTED";} ?>><?php echo $row_rsCategory['categoryDesc']?></option><?php} while ($row_rsCategory = mysql_fetch_assoc($rsCategory)); $rows = mysql_num_rows($rsCategory); if($rows > 0) { mysql_data_seek($rsCategory, 0); $row_rsCategory = mysql_fetch_assoc($rsCategory); }?></select>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10437-retain-combp-value-for-query/#findComment-40333 Share on other sites More sharing options...
millercepbs Posted June 1, 2006 Author Share Posted June 1, 2006 Did I lose you man? Quote Link to comment https://forums.phpfreaks.com/topic/10437-retain-combp-value-for-query/#findComment-40895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.