Jump to content

[SOLVED] Help creating "dynamic" links


ryanfc

Recommended Posts

I am creating a directory of local business where I live and need some help on the navigation I want to build for the site.

 

How it works:

I have 8 categories at the top of the page (Dining, Bars, Entertainment, etc).  When a user clicks on say the Dining button, it loads client_list.php and lists all businesses under that category.

 

Then on the left it loads a list of the sub categories (Pizza, Chinese, Fast Food, etc).  I have all that working, but what I want to do is when a user clicks on one of those side categories it loads a page called client_filter.php and loads only the businesses under that sub-category (say all the businesses under Pizza).  Now I have that link code partially done: client_filter.php/?category=$category_num&

 

but how do I code in the sub_category id number so that is only displays the Pizza places.

 

If any needs to see any of the other code just let me know.  Just don't want to show to much for security and such.

 

Link to comment
Share on other sites

here is the code for the client_list.php (i am kind of new at this so if anything seems stupid or there is an easier way just let me know)

 

 

<!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></title>

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

<?php
// took out the database connect info

$category_num = $_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());

$text_category = 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><?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_list['id']> {$sub['title']} </a> <br>";
} // end while
?></p></div>

<div id="centercontent">
  <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
  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 "<br><u>$letter</u><br>";
      } // end if
      
      // here we just echo out the name
      echo "{$info['name']} <br>";
  Print "Phone: ". $info['phone'] . "<br />";
      
      // 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
?></p>
</div>

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

Link to comment
Share on other sites

OK.. first as you said about secuirty..

i assume that $category_num expects a number.. if so

 

chage to

 

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

 

as your wide open to an SQL Injection (not good)

 

as for the question

but how do I code in the sub_category id number so that is only displays the Pizza places.

 

doesn't this line do that

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

 

and this line display them

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

Link to comment
Share on other sites

I did add that line as you suggested.

 

And I figured out my code error:

 

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

 

had sub_list not sub and forgot {}

Link to comment
Share on other sites

I just saved client_list.php as client_filter.php and when i click on the link in the left navigation all the graphics disappear when it loads client_filter.php.

 

 

Nevermind after client_filter.php I had /

took that out and it fixed the problem.

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.