仅在下拉列表中显示 X 条记录

发布于 2024-09-18 07:43:23 字数 1376 浏览 4 评论 0原文

有没有办法使用我发布的代码仅在下拉列表中显示一定数量的记录。我不是在谈论mysql中的LIMIT 0,5。我有 1000 条记录,它导致 IE 挂起。火狐浏览器很快。如果有人能给我一些指导,我将不胜感激。谢谢。

<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>


$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, $conn) or die(mysql_error());
$row_rsSuggest1 = mysql_fetch_assoc($rsSuggest1);
$totalRows_rsSuggest1 = mysql_num_rows($rsSuggest1);

is there a way with the code i have posted to only show a cretain amount of records in a dropdown list. i am not talking about the LIMIT 0,5 in mysql. i have 1000,s of records and it is causing IE to hang. firefox is quick. if someone could give me some guidance i would be grateful. thanks.

<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>


$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, $conn) or die(mysql_error());
$row_rsSuggest1 = mysql_fetch_assoc($rsSuggest1);
$totalRows_rsSuggest1 = mysql_num_rows($rsSuggest1);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风尘浪孓 2024-09-25 07:43:23

除非您稍后在代码中使用所有记录,否则最好使用 LIMIT 子句。这将通过扩展加速您的查询和脚本。查看一些分页脚本即可开始使用。

Unless you are using all the records later in the code, it is better to use a LIMIT clause. This will speed up your query and your script by extension. Look at some of the pagination scripts out there to get started.

夜夜流光相皎洁 2024-09-25 07:43:23

您可以更改插入 do{}while() 循环,使其在 5 个循环后停止,但如果您只打算使用 5 个循环,更好的答案是只从数据库中获取 5 个。

You could change your do{}while() loop that is inserting the <option> to stop after 5 loops, but if you're only going to use 5 the better answer is to only fetch 5 from the database.

帥小哥 2024-09-25 07:43:23

您可以通过将分页合并到下拉列表中来完成。这个想法是一次只显示少数项目,并提供“后退”/“下一步”按钮,允许用户查看更多内容。使用第三方库最容易完成此操作,但您也可以使用 CSS 和 Ajax 自行完成。

搜索具有分页支持的下拉列表。我没有使用过 PHP,所以我无法向您推荐任何好的 PHP 库。 http://www.nitobi.com/products/combobox/paging 似乎有一些东西/ 声称与 PHP 兼容,但似乎在 Firefox 中不起作用。您也可能有幸使用 YUI Paginator (http://developer.yahoo.com/yui/paginator /) 构建您自己的分页下拉列表。

另一种选择是将 Ajax 搜索支持添加到下拉列表中。这将允许用户输入他们正在搜索的内容,从而将列表从数千个减少到更小的列表。这是相当常见的,因此您应该不难找到库来执行此操作。

You can accomplish by incorporating paging into your dropdown list. The idea is to only show a handful of items at a time and provide Back/Next buttons that allow the user to view more. This is most easily done with a third-party library, but you can also do it yourself with CSS and Ajax.

Search for drop down lists with paging support. I haven't used PHP, so I can't point you to any good PHP libraries. There appears to be something at http://www.nitobi.com/products/combobox/paging/ that claims to be PHP compatible, but doesn't seem to work in Firefox. You might also have luck using the YUI Paginator (http://developer.yahoo.com/yui/paginator/) to build your own paging dropdown list.

Another option is to add Ajax search support to your dropdown list. This will allow the user to type what they are searching for, reducing the list from thousands to, hopefully, something much smaller. This is fairly common, so you shouldn't have trouble finding libraries to do this.

幸福不弃 2024-09-25 07:43:23
    $i = 0;
while ( $i < x ) {
$i++;
echo the records
}

我想这会起作用

    $i = 0;
while ( $i < x ) {
$i++;
echo the records
}

That'll work I think

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文