ryanfc Posted August 16, 2007 Share Posted August 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/ Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 you can comment out any passwords/domains etc but without code its kinda hard to say.. surly it will just be client_filter.php?category=$category_num&subcat=$subcat Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325855 Share on other sites More sharing options...
ryanfc Posted August 16, 2007 Author Share Posted August 16, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325861 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325883 Share on other sites More sharing options...
ryanfc Posted August 16, 2007 Author Share Posted August 16, 2007 but with that code i get this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/myevvspa/public_html/client_list.php on line 39 Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325886 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 i'm taking about changing $category_num = $_GET['category']; to $category_num = (int)$_GET['category']; i should of be clearer Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325889 Share on other sites More sharing options...
ryanfc Posted August 16, 2007 Author Share Posted August 16, 2007 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 {} Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325891 Share on other sites More sharing options...
ryanfc Posted August 16, 2007 Author Share Posted August 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65252-solved-help-creating-dynamic-links/#findComment-325906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.