Jump to content

Making use of data amongst |pipes|


Michan

Recommended Posts

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

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 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 ;D

I 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.