Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

dropdown list with paging help

Posted on 2010-09-09
6
359 Views
Last Modified: 2013-12-13
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

0
Comment
Question by:peter_coop
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:Marbleman
ID: 33636287

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

0
 

Author Comment

by:peter_coop
ID: 33636742
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
0
 
LVL 3

Accepted Solution

by:
Marbleman earned 250 total points
ID: 33637603
page is a parameter that you send to the php-script:

myCode.php?page=X

myCode.php?page=2 will give you rows 26 to 50
myCode.php?page=3 will give you entries 51 to 100


$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) {

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$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...


   }
}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  }
?>
</select>
</fieldset>
 </p>

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:peter_coop
ID: 33637710
where is page defined? as in $nPage = $_GET["page"];
thanks
0
 
LVL 3

Expert Comment

by:Marbleman
ID: 33650902
0
 

Author Closing Comment

by:peter_coop
ID: 33670839
thank you for help and link.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I'm getting too many results in this SELECT statement. How can I fix it? 6 55
SubQuery link 4 35
Currency in SQL? 2 29
Help in good tutorials for PHP, HTML and CSS 6 40
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question