Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageOn 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>
Post Follow-up to this message> 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
Post Follow-up to this messageOn 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!
Post Follow-up to this messageOn 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!
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.