PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old September 28th, 2002, 06:25 PM
spidermonster spidermonster is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Newcomerstown, ohio, usa
Posts: 151 spidermonster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to spidermonster Send a message via Yahoo to spidermonster
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>";
}
?>

Reply With Quote
  #2  
Old September 28th, 2002, 07:03 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
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:
php Code:
Original - php Code
  1.  
  2. SELECT * FROM links WHERE cat='1';

Reply With Quote
  #3  
Old October 1st, 2002, 06:43 PM
spidermonster spidermonster is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Newcomerstown, ohio, usa
Posts: 151 spidermonster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to spidermonster Send a message via Yahoo to spidermonster
RE: PHP Categories

Thanks nimco, im trying this right now...the littlest things confuse me...lol

Reply With Quote
  #4  
Old October 1st, 2002, 08:54 PM
spidermonster spidermonster is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Newcomerstown, ohio, usa
Posts: 151 spidermonster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to spidermonster Send a message via Yahoo to spidermonster
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

Reply With Quote
  #5  
Old October 1st, 2002, 09:11 PM
spidermonster spidermonster is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Newcomerstown, ohio, usa
Posts: 151 spidermonster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to spidermonster Send a message via Yahoo to spidermonster
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>";
}
?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > PHP Categories


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway