Jump to content

Putting List into Drop Down


ryanfc

Recommended Posts

I am working on a directory of businesses which has 8 main categories and each category has several sub-categories. Example: Dining is a Category with Pizza, Fast Food, Chinese, etc.  I have the sub-categories brought up in just a list on the left side of the page and when the user clicks on a sub-category it takes them from client_list.php to client_filter.php only showing businesses in that sub-category of the main category.  So only pizza places listed under dining.  However, I want to change the list to a (form) select box and then have the user click on the sub-category they want and then it takes them to the client_filter.php page to list only those bussinesses in that sub-categorie.  So after that long explanation how do I change my code to do that.  Here is my current code:

 

<?php
Print "<b>Filter:</b><br />";
while ($sub = mysql_fetch_array( $sub_list )) {
echo "<a href=client_filter.php?category=$category_num&sub_category={$sub['id']}> {$sub['title']}</a><br>";
} // end while
?>

 

 

Thanks for the help.

 

 

Link to comment
Share on other sites

ok I have been looking through previous posts but I am not finding a solution for my problem.  Maybe I am using the wrong terms or something.  I am still new at php and want to learn and understand the solution.  I know i need to but the input tags and other stuff into the php, what i don't know is how to get the value they select to the next page.  The way it works now is through a href link but that won't work for a form.  Any help on this would be appreciated.  Thank you.

Link to comment
Share on other sites

ok after messing around a bit I think I am getting closer to what I want but it is causing a bit of a problem.  Here is the code:

 

<form><?php
echo "<select name=\"names\">\n"; 
while($sub = mysql_fetch_array( $sub_list )) 
  { echo "<option name=\"".$sub['id']."\">".$sub['title']."</option>\n"; }
// end while
?></form>

 

Now the problem is my search box is now appearing on the left side below this form when it should be on the right hand side of the page.  Am I not closing something correctly?  Can anyone see a problem?

Link to comment
Share on other sites

well this is the html for the page.  anyone see the problem?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>myevvspace.com | premium local listings</title>

<link href="myevvspace_style.css" rel="stylesheet" type="text/css" />
<script src="navigation.js" type="text/javascript" language="javascript"></script>

<?php


$category_num = (int)$_GET['category'];

// Collects data from "friends" table
$data = mysql_query("SELECT name, phone FROM client WHERE category = '$category_num' order by name")
or die(mysql_error());

$sub_list = mysql_query("SELECT * FROM sub_category WHERE category = '$category_num' order by title")
or die(mysql_error());

$categorycrumb = mysql_query("SELECT title FROM category WHERE id = '$category_num'")
or die(mysql_error());

$location = mysql_query("SELECT title FROM category WHERE id = '$category_num'")
or die(mysql_error());

mysql_close ($conn);
?>

</head>

<body>
<div id="header"><?php include("includes/header.php"); ?></div>
<div id="navigation"><?php include("includes/navigation.php"); ?></div>
<div id="banner"><?php include("includes/ads/banner.php"); ?></div>
<div id="leftcontent"><p><form><?php
echo "<select name=\"names\">\n"; 
while($sub = mysql_fetch_array( $sub_list )) 
  { echo "<option name=\"".$sub['id']."\">".$sub['title']."</option>\n"; }
// end while
?></form>
</p>
  <form id="form1" name="form1" method="post" action="">
    submit
      <input type="submit" name="Submit" value="Submit" />
  </form>
  <p>  </p>
</div>

<div id="centercontent">
<div id="breadcrumb" align="right"><?php
Print "<a href=index.php class=breadcrumb>Home</a> :: ";
while ($crumb1 = mysql_fetch_array( $categorycrumb))
{ echo "<a href=client_list.php?category=$category_num class=breadcrumb>{$crumb1['title']}</a>"; }
?></div>
  <p><img src="images/welcome.gif" alt="Welcome" width="106" height="21" /></p>
  <p>Below you will find a list of all businesses under the <?php
  while ($userloc = mysql_fetch_array( $location))
  { echo "{$userloc['title']}"; } ?> category. Those companies that are paid advertisers can be clicked on for more detailed information.</p>
  <p>If you want to refine your search for a certain type of business just click on the list to the left.</p>
  <p>If you would like to become a paid advertiser and list your hours, location, menus, coupons and more please give us a call at (812) 402.1490.</p>
  <p> </p>
  <p>
<?php
$prev_row ='';
echo '<table class=results>';
while($info = mysql_fetch_array( $data )) {
$letter = strtoupper(substr($info['name'],0,1));
if ($letter != $prev_row) {
	if($count % 3) {
		for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
		echo '</tr>';
		$count =0;
	}
	$prev_row = $letter;
	echo '<tr bgcolor="#e7e7e7"><td colspan="3"><font color="#993833"><b>',$letter,'</b></font></td></tr>';
}
if ($count % 3 == 0) echo '<tr>';
$count++;
echo '<td>', $info['name'], '<br />Phone: ', $info['phone'], "</td>\n";
if ($count % 3 == 0) echo '</tr>';
}
if($count % 3) {
for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
echo '</tr>';
}
echo '</table>';
?></p>
</div>

<div id="searchbox" align="center"><form method="POST" action="search.php"><img src="images/spacer.gif" width="10" height="8" /><br /><input type="text" id="keyword" name="keyword" value="search" class="search" /></form></div>
<div id="rightcontent" align="center"><p>text</p></div>
</body>
</html>

Link to comment
Share on other sites

try this

<div id="leftcontent">
<form><?php
echo "<select name=\"names\">\n"; 
while($sub = mysql_fetch_array( $sub_list )) 
{
echo "<option name=\"".$sub['id']."\">".$sub['title']."</option>\n";
}
echo "</select>\n<br />"; 

?></form>
  <form id="form1" name="form1" method="post" action="">
    submit
      <input type="submit" name="Submit" value="Submit" />
  </form>
</div>

 

i closed the select and added a break

 

EDIT: as a note your form doesn't have a name, action, etc!

Link to comment
Share on other sites

ok one last question and hopefully i can mark this thread as solved.  When the user goes to client_list.php the sub_categories are being brought up into the form drop down list.  If a user then selects one of the options in the sub categories it takes them to client_filter.php.  But here is the problem it is not loading the business that go under that sub_category.  I will list the code for both pages...if anyone sees what I am doing wrong please let me know.  Thanks.

 

client_list.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>myevvspace.com | premium local listings</title>

<link href="myevvspace_style.css" rel="stylesheet" type="text/css" />
<script src="navigation.js" type="text/javascript" language="javascript"></script>

<?php

$category_num = (int)$_GET['category'];

// Collects data from "friends" table
$data = mysql_query("SELECT name, phone FROM client WHERE category = '$category_num' order by name")
or die(mysql_error());

$sub_list = mysql_query("SELECT * FROM sub_category WHERE category = '$category_num' order by title")
or die(mysql_error());

$categorycrumb = mysql_query("SELECT title FROM category WHERE id = '$category_num'")
or die(mysql_error());

$location = mysql_query("SELECT title FROM category WHERE id = '$category_num'")
or die(mysql_error());

mysql_close ($conn);
?>

</head>

<body>
<div id="header"><?php include("includes/header.php"); ?></div>
<div id="navigation"><?php include("includes/navigation.php"); ?></div>
<div id="banner"><?php include("includes/ads/banner.php"); ?></div>
<div id="leftcontent"><p><form action="client_filter.php"><?php
echo "<select name=\"subcat\">\n"; 
while($sub = mysql_fetch_array( $sub_list ))
{
  echo "<option name=\"".$sub['id']."\">".$sub['title']."</option>\n";
}
echo "</select>\n<br />"; ?>
<input type="submit" name="Submit" value="Submit" /></form>
</p>
  <p>  </p>
</div>

<div id="centercontent">
<div id="breadcrumb" align="right"><?php
Print "<a href=\"index.php\" class=\"breadcrumb\">Home</a> :: ";
while ($crumb1 = mysql_fetch_array( $categorycrumb))
{ echo "<a href=\"client_list.php?category=$category_num class=breadcrumb\">{$crumb1['title']}</a>"; }
?></div>
  <p><img src="images/welcome.gif" alt="Welcome" width="106" height="21" /></p>
  <p>Below you will find a list of all businesses under the <?php
  while ($userloc = mysql_fetch_array( $location))
  { echo "{$userloc['title']}"; } ?> category. Those companies that are paid advertisers can be clicked on for more detailed information.</p>
  <p>If you want to refine your search for a certain type of business just click on the list to the left.</p>
  <p>If you would like to become a paid advertiser and list your hours, location, menus, coupons and more please give us a call at (812) 402.1490.</p>
  <p> </p>
  <p>
<?php
$prev_row ='';
echo '<table class=results>';
while($info = mysql_fetch_array( $data )) {
$letter = strtoupper(substr($info['name'],0,1));
if ($letter != $prev_row) {
	if($count % 3) {
		for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
		echo '</tr>';
		$count =0;
	}
	$prev_row = $letter;
	echo '<tr bgcolor=#e7e7e7><td colspan=\"3\"><font color=#993833><b>',$letter,'</b></font></td></tr>';
}
if ($count % 3 == 0) echo '<tr>';
$count++;
echo '<td>', $info['name'], '<br />Phone: ', $info['phone'], "</td>\n";
if ($count % 3 == 0) echo '</tr>';
}
if($count % 3) {
for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
echo '</tr>';
}
echo '</table>';
?></p>
</div>

<div id="searchbox" align="center"><form method="POST" action="search.php"><img src="images/spacer.gif" width="10" height="8" /><br /><input type="text" id="keyword" name="keyword" value="search" class="search" /></form></div>
<div id="rightcontent" align="center"><p>text</p></div>
</body>
</html>

 

 

 

client_filter.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>myevvspace.com | premium local listings</title>

<link href="myevvspace_style.css" rel="stylesheet" type="text/css" />
<script src="navigation.js" type="text/javascript" language="javascript"></script>

<?php

$category_num = (int)$_GET['category'];
$sub_category_title = $_GET['subcat'];

// Collects data from "friends" table
$data = mysql_query("SELECT name, phone FROM client WHERE category = '$category_num' AND sub_category = '$sub_category_title' order by name")
or die(mysql_error());

$categorycrumb = mysql_query("SELECT title FROM category WHERE id = '$category_num'")
or die(mysql_error());

$subcategorycrumb = mysql_query("SELECT * FROM sub_category WHERE title = '$sub_category_title'")
or die(mysql_error());

mysql_close ($conn);
?>

</head>

<body>
<div id="header"><?php include("includes/header.php"); ?></div>
<div id="navigation"><?php include("includes/navigation.php"); ?></div>
<div id="banner"><?php include("includes/ads/banner.php"); ?></div>
<div id="leftcontent"><p>text</p></div>

<div id="centercontent">
<div id="breadcrumb" align="right"><?php
Print "<a href=index.php class=breadcrumb>Home</a> :: ";
while ($crumb1 = mysql_fetch_array( $categorycrumb))
{ echo "<a href=client_list.php?category=$category_num class=breadcrumb>{$crumb1['title']}</a> :: "; }
while ($crumb2 = mysql_fetch_array( $subcategorycrumb))
{ echo "<a href=client_filter.php?category=$category_num&sub_category=$sub_category_title class=breadcrumb>{$crumb2['title']}</a>";
} // end while
?></div><p><img src="images/welcome.gif" alt="Welcome" width="106" height="21" /></p>
  <p>Listed below are all the companies we have for this category.  Gold Advertisers have more info listed for them such as address, coupons, menues, etc.  Just click on the button for more information.  If you want to refine your search more just click on one of the categories to the left.  This text needs a lot of work, it is just filler for now.</p>
  <p><?php
$prev_row ='';
echo '<table class=\"results\">';
while($info = mysql_fetch_array( $data )) {
$letter = strtoupper(substr($info['name'],0,1));
if ($letter != $prev_row) {
	if($count % 3) {
		for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
		echo '</tr>';
		$count =0;
	}
	$prev_row = $letter;
	echo '<tr bgcolor=\"#e7e7e7\"><td colspan=\"3\"><font color=\"#993833\"><b>',$letter,'</b></font></td></tr>';
}
if ($count % 3 == 0) echo '<tr>';
$count++;
echo '<td>', $info['name'], '<br />Phone: ', $info['phone'], "</td>\n";
if ($count % 3 == 0) echo '</tr>';
}
if($count % 3) {
for ($i = ($count % 3); $i < 3; $i++) echo '<td> </td>';
echo '</tr>';
}
echo '</table>';
?></p>
</div></p>
</div>

<div id="searchbox" align="center"><form method="POST" action="search.php"><img src="images/spacer.gif" width="10" height="8" /><br /><input type="text" id="keyword" name="keyword" value="search" class="search" /></form></div>
<div id="rightcontent" align="center"><p>text</p></div>
</body>
</html>

Link to comment
Share on other sites

i think i know what the problem is

client_list.php

while ($crumb1 = mysql_fetch_array( $categorycrumb))
{ echo "<a href=\"client_list.php?category=$category_num class=breadcrumb\">{$crumb1['title']}</a>"; }

 

client_filter.php:

Print "<a href=index.php class=breadcrumb>Home</a> :: ";
while ($crumb1 = mysql_fetch_array( $categorycrumb))
{ echo "<a href=client_list.php?category=$category_num class=breadcrumb>{$crumb1['title']}</a> :: "; }
while ($crumb2 = mysql_fetch_array( $subcategorycrumb))
{ echo "<a href=client_filter.php?category=$category_num&sub_category=$sub_category_title class=breadcrumb>{$crumb2['title']}</a>";
} // end while

 

missing quotes

ie

<a href='client_list.php?category=$category_num' class='breadcrumb'>{$crumb1['title']}</a>

Link to comment
Share on other sites

I tried that, but it did not change anything.  However after starring at the code for awhile I think I know what the issue is, however I am not sure how to solve it.  The pay the database is set up for the client it just has a number for the Sub Category matching the number of that sub category in the Sub Category Table.  Meaning Pizza has an id number of 2.  Previously when I had the list of sub_categories (before it was in a form drop down), when a user clicked on the text link of the sub_category they wanted it was bringing over the id number for both the Category and Sub Category.  Now with the drop down menu it is only bringing the Title of the sub_category over.  Which is causing 2 problems:

 

1. since it is not bringing over the sub_category number this line:

$data = mysql_query("SELECT name, phone FROM client WHERE category = '$category_num' AND sub_category = '$sub_category_title' order by name")
or die(mysql_error());

does not work as the title of the sub_category is not in the client database just the number that goes with that sub_category.  And I have no idea how to fix that line to get the id number.

 

2. since the menu of the sub_categories is not longer bringing over the id number for both category and sub_category it is also messing up my breadcrumbs.

 

 

So I think the easiest solution is to have the drop down menu bring over the id number of the category and the sub_category.  But again I have no idea how to do that with a drop down menu.  If there is an easier solution I am all for hearing it.

 

If any of that does not make sense let me know and I will find another way to explain it.

Link to comment
Share on other sites

ok i changed the form on client_list.php to this

 

<form method="GET" action="client_filter.php"><?php
echo "<select name=subcat>\n"; 
while($sub = mysql_fetch_array( $sub_list ))
{
  echo "<option value=\"".$sub['category'].$sub['id']."\">".$sub['title']."</option>\n";
}
echo "</select>\n<br />"; ?>

 

and it is now bringing over both the category number and the sub category id numbers.  but obviously it is putting them together and bringing up the sub_category related to 12 which is Mongolian (category dining=1 and pizza is = 2.  so how do I separate the 2 values so it brings up the correct sub category on client_filter.php.

Link to comment
Share on other sites

a note:  the category will never be more than the first digit.  there are only 8 categories, so if I could some how pull out the first number and have it be the category number and set the remaining digit into the sub_category that would solve the problem.  so how do i do that?  is it the best way? (new to php so if there is an easier way to do what I am trying to do just let me know)

Link to comment
Share on other sites

ok i think i found the solution:

 

<form method="GET" action="client_filter.php"><?php
echo "<select name=subcat>\n"; 
while($sub = mysql_fetch_array( $sub_list ))
{
  echo "<option name=\"sub_category\" value=\"".$sub['id']."\">".$sub['title']."</option>\n";
}
echo "</select><input type=hidden name=category value=
$category_num />\n<br />"; ?>
<input type="submit" name="Submit" value="Submit" /></form>

 

 

if anyone finds a problem with doing like this let me know.  thanks.

Link to comment
Share on other sites

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.