Jump to content


Photo

Select where row=value OR where row=value?


  • Please log in to reply
6 replies to this topic

#1 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 13 July 2006 - 01:26 AM

here's the deal. I'm still working on the game review site. Each review has a section id, (2 digits, like "12") which are related to which platforms the game is on. An example:

12 - PS2
13 - Xbox
14 - PC
15 - PS2 and Xbox
16 - PS2 and Xbox and PC
17 - Xbox and PC

I have 2 lists of reviews, one for Xbox games, one for PS2 games. I was hoping to have MySQL select the results of rows with EITHER "12" OR "15" OR "16" on the PS2 list, so that on the Xbox list I could have it select 13 15 16 and 17. Is there an easy way to add this into my existing code? right now it's something like:

SELECT * FROM my_table WHERE sid = '12' ORDER BY title DESC
http://www.DaveLinger.com
dave at linger dot com

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 02:18 AM

do you have a field that contains the game type, like PS2, Xbox, or PC?
something like this:

sid    types:
12    PS2
13    Xbox
14    PC
15    PS2,Xbox
16    PS2,Xbox,PC


u know? it's much easier if you have a field in database which indicated the type of games for each review. 
Life's too short for arguing.

#3 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 13 July 2006 - 02:22 AM

I do, why does that matter?
http://www.DaveLinger.com
dave at linger dot com

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 02:31 AM

it is matter because you don't have to remember: id 12 is ps2, id 13 is xbox. u know

say you got a field called types, you can organize your query like this:

... where types like '%xbox%';

and it will return all row which contain xbox.

Life's too short for arguing.

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 13 July 2006 - 07:31 AM

SELECT * FROM my_table  WHERE sid IN (12,15,16) ORDER BY title DESC
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 10:26 AM

PS: Checking indexes/numbers is much faster than wildcard search, you should avoid it if unneccesary.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 13 July 2006 - 12:19 PM

Thanks guys.
http://www.DaveLinger.com
dave at linger dot com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users