Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Search for multiple items in one query...
This is probably blazingly obvious, but my SQL is shite.

I whant to have a field in a database for realted items. I nthat field I was
going to put the ID of the related items, seperated by ,s

For example in my related items, field....

18150,18170,18190

Ideally I would then feed that string into an SQL statement and return all 3
related items.

Now I know I could do an php explode() to generate an array() from my
string, then use that array to loop through and create a "multipart" query

SELECT * FROM my_table WHERE product = 1 OR product =2 OR product =3

My possibly futile or obvious question is: can I somehow avoid having to do
the explode() and OR stuff and just feed my string into my query?


TIA


Report this thread to moderator Post Follow-up to this message
Old Post
Bonge Boo!
11-22-04 01:56 AM


Re: Search for multiple items in one query...
On Sun, 21 Nov 2004 22:13:06 +0000, Bonge Boo! <bingbong@spamcop.net>
wrote:

>My possibly futile or obvious question is: can I somehow avoid having to do
>the explode() and OR stuff and just feed my string into my query?

If you use more than one table, then you can use the Relational
capabilities of MySQL.

Table one would have a unique ID field - call it, say, Serial. Don't
have the "Related items" data in this table - just the other stuff.

Table two should have a Serial field that will be identical to that in
Table one etc.

<http://www.keithjbrown.co.uk/vworks.../mysql_p5.shtml>
is quite a good introduction.

--
Interesting Xmas gifts: <http://www.awin1.com/tclick.php?id=405&mid=182> . <http:/
/BizOrg.co.uk/shopping/>
Locate your Mobile phone: <http://www.bizorg.co.uk/news.html>

Report this thread to moderator Post Follow-up to this message
Old Post
David Quinton
11-22-04 08:57 AM


Re: Search for multiple items in one query...

> Now I know I could do an php explode() to generate an array() from my
> string, then use that array to loop through and create a "multipart" query
>
> SELECT * FROM my_table WHERE product = 1 OR product =2 OR product =3

SELECT * FROM my_table WHERE product IN (1,2,3)

Floortje



Report this thread to moderator Post Follow-up to this message
Old Post
Floortje
11-22-04 01:59 PM


Re: Search for multiple items in one query...
On 22/11/04 7:52 am, in article 41a19b56$0$78738$e4fe514c@news.xs4all.nl,
"Floortje" <floortje- apestaartjexs4allpuntnl@hetminnetjehoort
.erbij> wrote:
 
>
> SELECT * FROM my_table WHERE product IN (1,2,3)

You're a lovely person. I go play now!


Report this thread to moderator Post Follow-up to this message
Old Post
Bonge Boo!
11-22-04 01:59 PM


Re: Search for multiple items in one query...
On 22/11/04 7:01 am, in article 0c33q0do6qeuif03j6h86uvvgl59kgl7ed@4ax.com,
"David Quinton" <usenet_2004D_email@REMOVETHISBITbizorg.co.uk> wrote:

> <http://www.keithjbrown.co.uk/vworks.../mysql_p5.shtml>
> is quite a good introduction.

Thank you!


Report this thread to moderator Post Follow-up to this message
Old Post
Bonge Boo!
11-22-04 01:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:34 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.