Michan Posted November 11, 2006 Share Posted November 11, 2006 Hi there,I'm trying to make sense of data displayed between pipes. A lot of the data in my database is stored between pipes, and I need to understand how this data can be used.For example, the product a news article is related to is displayed between pipes. If an article is related to just one product, it'll display in the database as (where '1' = the product ID):[b]|1|[/b]If it's related to two products, it'll display as:[b]|1|2|[/b]And so on.How can I seperate this data from the pipes? I need to be able to:[b]1)[/b] Display every product name on the article page.[b]2)[/b] Display every article related to a product on that product's page.Many thanks in advance :)- Mi Link to comment https://forums.phpfreaks.com/topic/26910-making-use-of-data-amongst-pipes/ Share on other sites More sharing options...
hostfreak Posted November 11, 2006 Share Posted November 11, 2006 http://www.php.net/explode , Give that a read. Should tell you everything you need. Link to comment https://forums.phpfreaks.com/topic/26910-making-use-of-data-amongst-pipes/#findComment-123073 Share on other sites More sharing options...
Psycho Posted November 11, 2006 Share Posted November 11, 2006 To find every product related to an article you could use explode() to transform the "|1|2|" value into an array split by the pipes. Note you would want to strip off hte first and last character, otherwise the first and last items in the array will be null. Then you could use the array to build a SELECT query to find all the products.To fin every article related to a product you would want to do a query on the articles table using a where clause something like this:"SELECT * FROM articles WHERE productlist LIKE '%|" . $prodID . "|%";A least I think it is the percent character to indicate any characters. Link to comment https://forums.phpfreaks.com/topic/26910-making-use-of-data-amongst-pipes/#findComment-123074 Share on other sites More sharing options...
Michan Posted November 11, 2006 Author Share Posted November 11, 2006 [quote author=mjdamato link=topic=114616.msg466416#msg466416 date=1163234792]To find every product related to an article you could use explode() to transform the "|1|2|" value into an array split by the pipes. Note you would want to strip off hte first and last character, otherwise the first and last items in the array will be null. Then you could use the array to build a SELECT query to find all the products.To fin every article related to a product you would want to do a query on the articles table using a where clause something like this:"SELECT * FROM articles WHERE productlist LIKE '%|" . $prodID . "|%";A least I think it is the percent character to indicate any characters.[/quote]Thank you very much ;DI think I've got it, as I can get it to return the results as the product numbers on their own, but how would I get about converting the numbers (productid) to the product names (name via the table 'products', where articles.productid = products.id)?Thanks again :)- Mi Link to comment https://forums.phpfreaks.com/topic/26910-making-use-of-data-amongst-pipes/#findComment-123077 Share on other sites More sharing options...
Psycho Posted November 11, 2006 Share Posted November 11, 2006 NOt knowing your table structure, this is just a guess.SELECT productnameFROM productsWHERE productid IN (prodID1, prodID2, etc.) Link to comment https://forums.phpfreaks.com/topic/26910-making-use-of-data-amongst-pipes/#findComment-123220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.