|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
PHP Categories
I want to make a categories for a search engine,,,
and i have no idea on going about it,,, this is all i have, and i dont understand how to put links under each category, and when that category is clicked, going to a results page with the links,,, this is all i have, and dont know what else to do... sql tables: CREATE TABLE `categories` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(70) NOT NULL ); CREATE TABLE `links` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `cat` INT NOT NULL, `url` VARCHAR(255) NOT NULL, `title` VARCHAR(255) NOT NULL, `keywords` VARCHAR(70) NOT NULL ); INSERT INTO categories VALUES (1, 'Business & Economy'); INSERT INTO categories VALUES (2, 'Computers & Internet'); INSERT INTO categories VALUES (3, 'News & Media'); INSERT INTO categories VALUES (4, 'Entertainment'); Dislpaying the categories : <? include('inc/mysql.php'); $query = "SELECT * FROM categories"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ echo "<font size="2"><b> <a href="$row[name]">$row[name]</a>$numbrows<BR>"; } ?> |
|
#2
|
|||
|
|||
|
RE: PHP Categories
Well you're going the right way about it. Like you've done, when you add a page to the search engine you need to add a reference to a category (category ID). This then references to a category in another table.
If you want to run a query to select all pages in a category, try: |
|
#3
|
|||
|
|||
|
RE: PHP Categories
Thanks nimco, im trying this right now...the littlest things confuse me...lol
|
|
#4
|
|||
|
|||
|
RE: PHP Categories
Thanks again Nimco, here is a working example:
http://www.spidermonster.com/projects/search/search.php now,,,im trying to figure how to do subcategories...lol figured it could be a lil similiar to the code already there, and trying to figure out how to search, but plenty of tutorials on that... my bigest problem is, using if and else statements or figuring out how to use all the same code on one page, for results, using categories, and search results in one page. results.php. in some cgi scripts ive seen Pars_form, and searchstring variable and a addurl variable, categories variable... thats something id like to learn more about in php,,, how to parse a form or seperate the code one php script so one code doesnt interfere with the other... Anyone know where i can get ahold of these tutorials? Thanks Thanks again Nimco |
|
#5
|
|||
|
|||
|
RE: PHP Categories
Sorry for so many posts, this is going to be last one, just wanted to post the code so everyone can try it themselves. dont know if it will be helpful,
------------------------------------- mysql.schema: ------------------------------------- CREATE TABLE `categories` ( `cat_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(70) NOT NULL ); CREATE TABLE `links` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `cat_id` INT NOT NULL, `url` VARCHAR(255) NOT NULL, `title` VARCHAR(255) NOT NULL, `desc` VARCHAR(255) NOT NULL, `keywords` VARCHAR(70) NOT NULL ); INSERT INTO categories VALUES (1, 'Business & Economy'); INSERT INTO categories VALUES (2, 'Computers & Internet'); INSERT INTO categories VALUES (3, 'News & Media'); INSERT INTO categories VALUES (4, 'Entertainment'); INSERT INTO links VALUES ('', '1', 'http://www.spidermonster.com', 'SpiderMonster.com', 'New Search Engine on the web! If we can figure out this code...lol', 'search, engine, chat, classifieds,'); INSERT INTO links VALUES ('', '2', 'http://www.url.com', 'title2', 'Description2', 'keywords2'); INSERT INTO links VALUES ('', '3', 'http://www.url.com', 'title3', 'Description3', 'keywords3'); INSERT INTO links VALUES ('', '4', 'http://www.url.com', 'title4', 'Description4', 'keywords4'); ------------------------------------- mysql.php: ------------------------------------- <? $location = 'localhost'; $username = 'username'; $password = 'password'; $database = 'database'; $conn = mysql_connect("$location","$username","$password"); if (!$conn) die ("Could not connect MySQL"); mysql_select_db($database,$conn) or die ("Could not open database"); ?> ------------------------------------- categories.php: ------------------------------------- <? include('../../inc/mysql.php'); $query = "SELECT * FROM categories"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ echo "<font size="2"><b> <a href="results.php?cat_id=$row[cat_id]">$row[name]</a><BR>"; } ?> ------------------------------------- results.php: ------------------------------------- <? include('../../inc/mysql.php'); $query = "SELECT * FROM links WHERE cat_id='$cat_id'"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ echo "<font size="2"><b> <a href="$row[url]">$row[title]</a><BR>$row[desc]<BR>"; } ?> |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > PHP Categories |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|