Jump to content

Recommended Posts

Hi, i have a script that loads a CSV file and divides it in parts.

It is made for a music store so it has:

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 the products are being shown in one lightbox, 12 products to be precise, with a next and previous button

The products that are shown are the products that are sorted from the group.

So there are different pages to choose from, from the website, depending on the group number

 

What i like to have is that there is a dropdown list in top of the page, with ALL the brands from that precise group, so if chosen, only the products from that brand are shown.

I have the dropdown menu, and i can load a $part[6], but it only shows the brand of one product, there is no list.

Can someone point me in the right direction ?

Here is the script:

 

<html>
<head>
</head>
<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 

while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 0) && (!feof($file_handle)))
{
    //new code
    //skip first $offset lines  
  
$num = count($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; ">

<option value="1"><?php echo $parts[6]; ?>
</option>
</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>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/201363-drop-down-list-from-a-csv/
Share on other sites

Ok, so here's what is up.  You will need to assemble an array while you loop through your while($parts=fget...)

 

<html>
<head>
</head>
<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=new 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>

 

Also you are using the <html> tag incorrectly.

I found the problem and the page loads without errors, i can see the dropdown list, and i can select the brands but then nothing happens.

Here is the new code:

 

<html>
<head>
</head>
<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>

The problem is now, that the brands are not clickable, maybe i didn't explain it too well ;-)

I need the brands to be clickable so that people can sort the page easier.

The other problem is that it only shows the brands from products that are currently loaded into the page, if i press on next page, i get more brands, but i need all the brands to be there, loaded at the first page, is that possible ?

  • 4 weeks later...

I've been working on this since my last post, but i am still a little puzzled.

There are some things not working right in this script.

 

-I do not see all the brands from the particular group in the dropdown, only see the brands that are currently on the page, if i go to the next page i see more brands, but if i go back again i see only the first page brands.

 

-The links in the dropdown are clickable but do not point anywhere, i wanted to make a offset behind my link that will search for the brand and only displays the brand but i do not know how to do that

 

-Some of the brands are double in the dropdownlist, also they are not sorted :-(

 

Here is the website:

http://www.dwmusicstore.com/mark2/occasiona.php

 

And here is the script:


<html>
<head>
</head>
<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>

<?PHP

// PHP code loading the CSV file, than dividing it in parts, also counting how many products are shown on the page.


$SelectArray=array();
$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

while ((($parts = fgetcsv($file_handle,4096,"|")) !== FALSE)  && ($LinesToDisplay > 0) && (!feof($file_handle)))
{
$SelectArray[]=$parts[6];

    //new code
    //skip first $offset lines  

$num = count($parts[6]);


//giving $parts[5] (group number) it's number

if ($parts[5] == 9999)
{

if ($offset-- > 0)  
{continue;}

//making $parts[0] & $parts[1] lowercase

$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));
?>
<td>

<?php
//creating a small table cell where the $parts are being displayed

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>";
?>

<div onMouseOver="this.style.color = 'black';" onMouseOut="this.style.color = '#D5DF23';">

<?php
//displaying the $parts[1] which has a mouseover and closing the DIV

echo "<font size=2>-$parts[1]</font>";
echo "</div></i>";

//displaying 2 clickable buttons, 1 for questions and the other for ordering the products, they have a title mouseover 
?>

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

<?php
//displaying the price in a little red cell

echo "€  $parts[2]";

?>
</b>
</td>
</tr>
</table>

<?php
//displaying the stock value's in both the stores

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;'>";

//displaying how many products are shown

      $LinesToDisplay--;

if ($LinesToDisplay/3==intval($LinesToDisplay/3))
{
   echo "<tr><td>";
}
     }}

fclose($file_handle);
?>

<tr align=right>
<form name=jump>
<select name="menu" style="background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: none; font-size: 12; width: 150px; ">

<?php

//dropdown menu showing the brands, at the moment not showing all the brands from the group, links are not good directed

foreach ($SelectArray as $val){
echo "<option value=\"?offset=$val\">$val</option>\n";
$i++;
}
?> 
</select>
<input type="button" onClick="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO"></form>

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

If you only want one, you can do "SELECT DISTINCT" but you want the duplicates because they result from 2 items from the same manufacturer.  What you want is to extend the details of the select (such as adding product short description).  If you want them ordered, append to your query:

 

ORDER BY col_name [ASC | DESC]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.