Jump to content

What am I doing wrong?


ryanfc

Recommended Posts

My site is a local directory of businesses and when a user clicks on a category such as Dining it takes them to a page called client_list.php.  This page lists all the business under that category.  Then if the user wants to filter the results a bit they can choose a sub_category from the left side of the page such as Barbeque.  Which will take the user to client_filter.php and only lists those places that are listed as Barbeque restaureants.  So here is my problem when the user uses the filter it is only listing the places under that sub_category put is listing it several times and showing it under ever sub_category that is in the database.  You can see what I mean if you go here: http://myevvspace.com/client_list.php?category=1 then  choose Barbeque.  Can anyone help me figure out why it is doing that?

 

 

Here is the code for the page...

<!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_num = (int)$_GET['subcat'];

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

$filtertext = mysql_query("SELECT title FROM category WHERE id = '$category_num'")
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 id = '$sub_category_num'")
or die(mysql_error());

$sub_list = mysql_query("SELECT * FROM sub_category WHERE category = '$category_num' order by title")
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>



<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="126" rowspan="2" align="left" valign="top" id="leftcontent">
<br /><form class="filter" method="get" action="client_filter.php">
          <?php
$cat1 = "Select a Cuisine:<br />";
$cat2 = "Select a Bar Type:<br />";
$cat3 = "Select your Entertainment:<br />";
$cat4 = "Select an Art:<br />";
$cat5 = "Select a Lodging:<br />";
$cat6 = "Select a Community:<br />";
$cat7 = "Select a Real Estate:<br />";
$cat8 = "Select a Service:<br />";

$current_category = $category_num;

if ($current_category == 1) {
echo $cat1;
}
elseif ($current_category == 2) {
echo $cat2;
}
elseif ($current_category == 3) {
echo $cat3;
}
elseif ($current_category == 4) {
echo $cat4;
}
elseif ($current_category == 5) {
echo $cat5;
}
elseif ($current_category == 6) {
echo $cat6;
}
elseif ($current_category == 7) {
echo $cat7;
}
elseif ($current_category ==  {
echo $cat8;
}
echo "<select class=\"filter\" 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\" /><div align=\"right\"><input class=\"filter\" type=\"submit\" name=\"Search\" value=\"Search\" /></div>"; ?>
    </form></div></td>
    <td rowspan="2" align="left" valign="top" id="centercontent"><div id="breadcrumb" align="right">
      <?php
Print "<a href=index.php class=breadcrumb>Home</a> :: ";
while ($crumb1 = mysql_fetch_array( $categorycrumb))
{ echo "{$crumb1['title']}"; }
?></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
echo '<table class=results cellpadding=3 cellspacing=0><tr height=18><td width=31% align=center bgcolor=#D5CB9A background=images/table_gradient.jpg><font class=result><b>Business Name</b></font></td><td width=29% align=center bgcolor=#D5CB9A background=images/table_gradient.jpg><font class=result><b>Address</b></font></td><td width=20% align=center bgcolor=#D5CB9A background=images/table_gradient.jpg><font class=result><b>Phone Number</b></font></td><td width=20% align=center bgcolor=#D5CB9A background=images/table_gradient.jpg><font class=result><b>Type</b></font></td></tr>';
  while ($info = mysql_fetch_array( $data )) {
      // get the first letter of the name. let's convert
      // it to uppercase to make sure that 'A' and 'a' get
      // put into the same group. 
      $letter = strtoupper(substr($info['name'],0,1));
      
      // now we will check to see if the first letter of the
      // current name is the same as the first letter of the
      // previous name. If it is not, then we make a new
      // group 'header' with the letter. Since there is no 
      // previous row on the first pass, we will automatically
      // have an underlined 'A' made (or whatever your list starts with) 
      if ($letter != $prev_row) {
         echo '<tr><td height=18 colspan=4 bgcolor=#eeeeee><font class=result color=#585858><b>',$letter,'</b></font></td></tr>';
      } // end if
       echo '<tr>';
      // here we just echo out the name
      if ($info['paid'] == 1)
    echo "<td class=results><font class=result><a href=\"client_detail.php?category={$info['category']}&sub_category={$info['sub_category']}&client={$info[0]}\"><b>", $info['name'], '</b></a></font></td><td class=results><font class=result>', $info['address'], '</font></td><td class=results align=center><font class=result>', $info['phone'], '</font></td><td class=results align=center><font class=result_type>', $info['title'], '</font></td>';
else
    echo '<td class=results><font class=result>', $info['name'], '</font></td><td class=results><font class=result>', $info['address'], '</font></td><td class=results align=center><font class=result>', $info['phone'], '</font></td><td class=results align=center><font class=result_type>', $info['title'], '</font></td>';
      
      // and here we assign the current letter to $prev_row so 
      // that on the next iteration of the loop, we will have 
      // a previous row letter to compare
      $prev_row = $letter;
   } // end while
   
   echo '</tr></table>';
?>
      </p>
    <p> </p></td>
    <td height="34" align="center" valign="middle" id="searchbox"><form method="post" action="search.php" style="display:inline"><input type="text" id="keyword" name="keyword" value="search" class="search" /></form></td>
  </tr>
  <tr>
    <td width="126" align="center" valign="top" id="rightcontent">right content for ads</td>
  </tr>
</table>
</body>
</html>

 

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.