我怎样才能有一个工作下拉列表,其中包含 php 中 csv 的链接

发布于 2024-09-01 12:16:49 字数 5122 浏览 4 评论 0原文

我有一个网站,可以加载 CSV、将其分为几个部分并显示这些部分。

有 7 个部分,因为它是针对音乐商店的,所以它是这样切片的:

  • 产品名称
  • 子名称
  • 价格
  • 一家商店的库存
  • 另一家商店的库存
  • 组名称
  • 品牌名称

我现在拥有的是它在一页上显示 12 个产品,页面顶部有下一个和上一个链接。 这些页面是用组名称制作的,每个组都有自己的页面,所以你有鼓页面、吉他页面、扬声器页面。 这一切都很好。 我在那里编写的是一个下拉列表,它会下拉一个品牌名称列表,这应该缩小对正在查看产品的人的搜索范围。 现在的问题是,下拉菜单有效,我看到了品牌,但它们不可点击,仅显示当前页面上的品牌,因此并非显示该组中的所有品牌,仅显示 12 个品牌目前正在显示,当您按“下一步”时,它会显示另外 12 个品牌,但我希望它们能够在开始时显示。 第三个问题是,当它显示品牌时,它会显示两倍或三倍的品牌,具体取决于有多少产品具有相同的品牌。 以这段代码为基础,有我想要的方法吗?

<html>
<body bgcolor=#E2E965 link=black vlink=black alink=black text=#D5DF23>
<style type="text/css">
#nav, #nav ul {
padding: 0;
margin: 0;
list-style: none;
}
#nav li {
float: left;
width: 120px;
}
#nav ul {
position: absolute;
width: 120px;
left: -1000px;
}
#nav li:hover ul {
left: auto;
}
<!--
a {text-decoration:none}
//-->
body
{
scrollbar-arrow-color: #E2E965;
scrollbar-face-color: #D7182A;
scrollbar-highlight-color: #000000;
scrollbar-3dlight-color: #D6DF23;
scrollbar-shadow-color: #00000;
scrollbar-darkshadow-color: #00000;
scrollbar-track-color: #D6DF23;
}
input:link {text-decoration: none; color: #E2E965;}
input:visited {text-decoration: none; color: #E2E965;}
input:active {text-decoration: none; color: #E2E965;}
.spacer_black {
margin: 0px;
padding: 0px;
border: 5px;
height: 2px;
width: 100%;
line-height: 0px;
font-size: 0px;
background-color: #000000;}
</style>
<table width=800 border=0><td>
</html>
<?PHP
$offset = isset($_GET['offset'])?$_GET['offset']:0;
$LinesToDisplay = 12;
$row = $offset + $LinesToDisplay;
$row2 = $offset - $LinesToDisplay;
$file_handle = fopen("web.txt", "rb");
error_reporting( E_ALL ); // DEBUGGING
$SelectArray=array();
while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 0) && (!feof($file_handle)))
{
    //new code
    //skip first $offset lines  

$num = count($parts[6]);
$SelectArray[]=$parts[6];
if ($parts[5] == 9999)
{
if ($offset-- > 0)   
{continue;}
$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));
?>
<td>
<?php
echo "<table BACKGROUND='background.jpg' border=0 width=250><td width='243' height='105'>";
echo "<font size=-1 face='helvetica' color=#812990><b>$parts[0]</b></font>";
echo "<i>";
?>
<html>
<div onMouseOver="this.style.color = 'black';" onMouseOut="this.style.color = '#D5DF23';">
</html><?php
echo "<font size=2>-$parts[1]</font>";
echo "</div></i>";
?><html><a href="#" title="Koop nu de <?php echo $parts[0]; ?>" onClick="window.open('form.php?p=<?php echo urlencode($parts[0]); ?>','popuppage','width=400,height=400,top=250,left=250,resizable=0,statusbar=0,titlebar=yes,toolbar=no,scrollbars=no,location=no,directories=no');">
<div><img src='ster.jpg' border=0 width='46' align='right'></a>
<a href="#"><img src='envelope.jpg' border=0 width='46' align='right'title="Heeft u een vraag over <?php echo $parts[0]; ?>" onClick="window.open('vraag.php?p=<?php echo urlencode($parts[0]); ?>','popuppage','width=400,height=400,top=250,left=250,resizable=0,statusbar=0,titlebar=yes,toolbar=no,scrollbars=no,location=no,directories=no');">
<div></a>
<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'>
<TR>
<TD WIDTH='70' HEIGHT='20' BACKGROUND='pricebackground.jpg' VALIGN='bottom'>
<center>
<font size=2 color=white face='helvetica'>
<b></html>
<?php echo "€  $parts[2]";
?>
</b>
</td>
</tr>
</table>
<?php echo "<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>";
      echo ("<font color=black> Amsterdam </font>");
      if ( $parts[3] >= 1 )  echo ("<IMG SRC =green.gif>")."";
      if ( $parts[3] <= 0 )  echo ("<IMG SRC =red.gif>")."";
      echo ("<font color=black> Utrecht </font>");
      if ( $parts[4] >= 1 )  echo ("<IMG SRC =green.gif>")."</td></table></b><p style='margin:9px;'>";
      if ( $parts[4] <= 0 )  echo ("<IMG SRC =red.gif>")."</td></table></b><p style='margin:9px;'>";
      $LinesToDisplay--;
if ($LinesToDisplay/3==intval($LinesToDisplay/3))
{
   echo "<tr><td>";
}
     }}
fclose($file_handle);
?>
<tr align=right>
<select style="background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: none; font-size: 12; width: 150px; ">
<?php
$i=1;
foreach ($SelectArray as $val){
echo "<option value=\"$i\">$val</option>\n";
$i++;
}
?>
</select>
<font color=black><body alink=black vlink=black link=black text=black>
<center><a href="occasiona.php?offset=<?php echo $row2; ?>" align=center>&laquo; previous</a> || <a href="occasiona.php?offset=<?php echo $row; ?>">next &raquo;</a></table></html>

I have a website that loads a CSV, divides it into parts, and shows these parts.

There are 7 parts, and since it is for a music store it is sliced like this:

  • the name of the product
  • the subname
  • the price
  • the stock in one shop
  • the stock of the other shop
  • the group name
  • the brandname

What i have now is that it shows 12 products on 1 page, with a next and previous link on top of the page.
The pages are made with the group name, every group has it's own page, so you have a drums page, guitar page, speaker page.
That all works great.
What i programmed in there is a dropdownlist, it drops down a list of brandnames, which should narrow the search for a person who is looking at the products.
Problem is right now, that the dropdown menu works, i see the brands, but they are NONE clickable, only the brands that are currently on the page are shown, so NOT all the brands from that group are shown, only the 12 that are currently showing, when you press next, it shows 12 more brands, but i want them to be shown right on the start.
And the third problem is, when it is showing the brands, it shows them double or triple, depending on how many products have the same brand.
Is there a way what i want, with this code as a basis ?

<html>
<body bgcolor=#E2E965 link=black vlink=black alink=black text=#D5DF23>
<style type="text/css">
#nav, #nav ul {
padding: 0;
margin: 0;
list-style: none;
}
#nav li {
float: left;
width: 120px;
}
#nav ul {
position: absolute;
width: 120px;
left: -1000px;
}
#nav li:hover ul {
left: auto;
}
<!--
a {text-decoration:none}
//-->
body
{
scrollbar-arrow-color: #E2E965;
scrollbar-face-color: #D7182A;
scrollbar-highlight-color: #000000;
scrollbar-3dlight-color: #D6DF23;
scrollbar-shadow-color: #00000;
scrollbar-darkshadow-color: #00000;
scrollbar-track-color: #D6DF23;
}
input:link {text-decoration: none; color: #E2E965;}
input:visited {text-decoration: none; color: #E2E965;}
input:active {text-decoration: none; color: #E2E965;}
.spacer_black {
margin: 0px;
padding: 0px;
border: 5px;
height: 2px;
width: 100%;
line-height: 0px;
font-size: 0px;
background-color: #000000;}
</style>
<table width=800 border=0><td>
</html>
<?PHP
$offset = isset($_GET['offset'])?$_GET['offset']:0;
$LinesToDisplay = 12;
$row = $offset + $LinesToDisplay;
$row2 = $offset - $LinesToDisplay;
$file_handle = fopen("web.txt", "rb");
error_reporting( E_ALL ); // DEBUGGING
$SelectArray=array();
while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 0) && (!feof($file_handle)))
{
    //new code
    //skip first $offset lines  

$num = count($parts[6]);
$SelectArray[]=$parts[6];
if ($parts[5] == 9999)
{
if ($offset-- > 0)   
{continue;}
$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));
?>
<td>
<?php
echo "<table BACKGROUND='background.jpg' border=0 width=250><td width='243' height='105'>";
echo "<font size=-1 face='helvetica' color=#812990><b>$parts[0]</b></font>";
echo "<i>";
?>
<html>
<div onMouseOver="this.style.color = 'black';" onMouseOut="this.style.color = '#D5DF23';">
</html><?php
echo "<font size=2>-$parts[1]</font>";
echo "</div></i>";
?><html><a href="#" title="Koop nu de <?php echo $parts[0]; ?>" onClick="window.open('form.php?p=<?php echo urlencode($parts[0]); ?>','popuppage','width=400,height=400,top=250,left=250,resizable=0,statusbar=0,titlebar=yes,toolbar=no,scrollbars=no,location=no,directories=no');">
<div><img src='ster.jpg' border=0 width='46' align='right'></a>
<a href="#"><img src='envelope.jpg' border=0 width='46' align='right'title="Heeft u een vraag over <?php echo $parts[0]; ?>" onClick="window.open('vraag.php?p=<?php echo urlencode($parts[0]); ?>','popuppage','width=400,height=400,top=250,left=250,resizable=0,statusbar=0,titlebar=yes,toolbar=no,scrollbars=no,location=no,directories=no');">
<div></a>
<TABLE BORDER='0' cellpadding='0' CELLSPACING='0'>
<TR>
<TD WIDTH='70' HEIGHT='20' BACKGROUND='pricebackground.jpg' VALIGN='bottom'>
<center>
<font size=2 color=white face='helvetica'>
<b></html>
<?php echo "€  $parts[2]";
?>
</b>
</td>
</tr>
</table>
<?php echo "<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>";
      echo ("<font color=black> Amsterdam </font>");
      if ( $parts[3] >= 1 )  echo ("<IMG SRC =green.gif>")."";
      if ( $parts[3] <= 0 )  echo ("<IMG SRC =red.gif>")."";
      echo ("<font color=black> Utrecht </font>");
      if ( $parts[4] >= 1 )  echo ("<IMG SRC =green.gif>")."</td></table></b><p style='margin:9px;'>";
      if ( $parts[4] <= 0 )  echo ("<IMG SRC =red.gif>")."</td></table></b><p style='margin:9px;'>";
      $LinesToDisplay--;
if ($LinesToDisplay/3==intval($LinesToDisplay/3))
{
   echo "<tr><td>";
}
     }}
fclose($file_handle);
?>
<tr align=right>
<select style="background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: none; font-size: 12; width: 150px; ">
<?php
$i=1;
foreach ($SelectArray as $val){
echo "<option value=\"$i\">$val</option>\n";
$i++;
}
?>
</select>
<font color=black><body alink=black vlink=black link=black text=black>
<center><a href="occasiona.php?offset=<?php echo $row2; ?>" align=center>« previous</a> || <a href="occasiona.php?offset=<?php echo $row; ?>">next »</a></table></html>

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

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

发布评论

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

评论(2

狠疯拽 2024-09-08 12:16:49

您确定偏移量,然后用 12 行填充 $SelectArray。这样,您的脚本就无法知道 .csv 中还有什么内容,并且除了从文件中获取的数据之外,它无法显示任何内容。

如果您想显示所有品牌,则需要导入完整的 .csv。根据该文件的大小,这可能不是一个好主意,因为每次加载页面时都会加载完整的文件。如果可能:请改用数据库,导入 .csv 并仅选择必要的信息。

You determine the offset and then fill $SelectArray with 12 lines. That way your script has no way of knowing what else is in the .csv, and it can't display anything except for the data you got from the file.

If you want to display all the brands you need to import the full .csv. Depending on how larget that file is, this might nog be a good idea, because you'll be loading that complete file every time you load the page. If it's a possibility: use a database instead, import the .csv and select only the necessary information.

别在捏我脸啦 2024-09-08 12:16:49

目前该文件只有180kbytes,所以这没有问题,问题是如何做到这一点。

At the moment the file is only 180kbytes so that is no problem, the problem is how to do it.

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