Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


 
 
LinkBack Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 12-21-2008, 08:50 PM   #1 (permalink)
v7n Mentor
 
Join Date: 10-13-03
Location: Atlanta, GA
Posts: 662
iTrader: 0 / 0%
Latest Blog:
None

Leon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of lightLeon is a glorious beacon of light
Some PHP / MySQL Help.

Hey Folks I need a little help. I want to display rows from a table that have a certain value in their column. I know how to do this for just 1 and that's:
PHP Code:
$cat $_GET['cat'];

if (empty(
$_GET['cat'])) { $query "SELECT * FROM cat_ballpythons ORDER BY priority DESC"; }
else { 
$query "SELECT * FROM cat_ballpythons WHERE cat1='$cat' ORDER BY priority DESC";}
$result = @mysql_query($query); 
What I need to know is how to do it for more than 1 variable [like $cat2 and $cat3] and only if that variable is defined. For instance if none of the categories are defined it should display all items but if only 1 and 2 it should only what was chosen for categories #1 and #2. I attempted this with:

PHP Code:
$cat $_GET['cat'];
$cat2 $_GET['cat2'];
$cat3 $_GET['cat3'];

if (empty(
$_GET['cat3'])) { $query "SELECT * FROM cat_ballpythons WHERE cat1='$cat' AND cat2='$cat2' ORDER BY priority DESC"; }
elseif (empty(
$_GET['cat2'])) { $query "SELECT * FROM cat_ballpythons WHERE cat1='$cat' ORDER BY priority DESC"; }
elseif (empty(
$_GET['cat'])) { $query "SELECT * FROM cat_ballpythons ORDER BY priority DESC"; }
else { 
$query "SELECT * FROM cat_ballpythons WHERE cat1='$cat' AND cat2='$cat2' AND cat2='$cat3' ORDER BY priority DESC"; } 
But it doesn't work. I also need to know how to keep it from displaying the same tables over again if the variables are the same. Like say if Item #1 has "Stuff" in Cat1 and "Whatever" in Cat2 and "Nothing" in Cat3 I don't want it to be displayed 3 times if:

PHP Code:
page.php?cat1=stuff&cat2=whatever&cat3=nothing 
The Overall goal needs to be that I need to be able to specify 3 variables from a table row and then echo the items that are equal to the query.

Last edited by Leon; 12-21-2008 at 09:01 PM..
Leon is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL? rob7676 Coding Forum 5 07-11-2008 05:53 PM
Need help with PhP MySQL JustRetarded Coding Forum 4 08-16-2007 12:12 AM
MYSQL gatorgritz Web Design Lobby 7 07-05-2006 11:24 PM
MySQL help cbolts Web Design Lobby 2 04-09-2004 07:39 AM
PHP/mySQL SN3 Coding Forum 5 02-03-2004 10:38 PM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 03:22 AM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.