Link to home
Start Free TrialLog in
Avatar of peter_coop
peter_coopFlag for United Kingdom of Great Britain and Northern Ireland

asked on

dropdown list with paging help

hi
is there a way to have a dropdown say where it loads the first 100 records then some kind of paging feature to read the next 100 etc within the dropdown. i have posted my code and would be grateful if someone could help me get started with this? many thanks
$colname_rsSuggest1 = "-1";
if (isset($_SESSION['kt_idcode_usr'])) {
  $colname_rsSuggest1 = (get_magic_quotes_gpc()) ? $_SESSION['kt_idcode_usr'] : addslashes($_SESSION['kt_idcode_usr']);
}
mysql_select_db($database_conn, $conn);
$query_rsSuggest1 = sprintf("SELECT DISTINCT `boxref` FROM `files` WHERE customer = '%s' AND boxstatus = 1 ORDER BY boxref ASC", $colname_rsSuggest1);
$rsSuggest1 = mysql_query($query_rsSuggest1, $logistor) or die(mysql_error());
$row_rsSuggest1 = mysql_fetch_assoc($rsSuggest1);
$totalRows_rsSuggest1 = mysql_num_rows($rsSuggest1);

<p><fieldset><legend class="style8">Select a Box</legend>
<select name="suggestTextField1" id="suggestTextField1">
<option value="">Select a Box</option>
<?php
do {  
?>
<option value="<?php echo $row_rsSuggest1['boxref']?>"><?php echo $row_rsSuggest1['boxref']?></option>
<?php
} while ($row_rsSuggest1 = mysql_fetch_assoc($rsSuggest1));
  $rows = mysql_num_rows($rsSuggest1);
  if($rows > 0) {
      mysql_data_seek($rsSuggest1, 0);
	  $row_rsSuggest1 = mysql_fetch_assoc($rsSuggest1);
  }
?>
</select>
</fieldset>
 </p>

Open in new window

Avatar of Marbleman
Marbleman


If you want to step in pages you could pass the requested page to PHP-Page as a param like ?page=5
Then you walk trough the rowset to the appropriate entry and continute your output from there

$nPage = $_GET["page"];

$nCount = mysql_num_rows($rsSuggest1))
$nMaxPerPage = 25;
$nMaxPage = ceil($nCount / $nMaxPerPage) - 1;
if ($nMaxPage > 0)
{
   $nPage = min(max($nPage, 0), $nMaxPage);
   mysql_data_seek($result, $nPage * $nMaxPerPage);

   //walk through the next $nMaxPerPage rows:
   for($i = 1; $i < $nMaxPerPage; $i++) {

       $row_rsSuggest1 = mysql_fetch_assoc($rsSuggest1);
       //perform output or something else here...


   }
}

Open in new window

Avatar of peter_coop

ASKER

thanks for reply. 2 questions. where is this parameter from: $nPage = $_GET["page"];
and also, could you mark up your example in my code? thanks
ASKER CERTIFIED SOLUTION
Avatar of Marbleman
Marbleman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
where is page defined? as in $nPage = $_GET["page"];
thanks
thank you for help and link.