SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    implode() and explode()

    HI All

    I have been playing around with implode() and explode()

    Now we have a HTML form like the one I posted in a previuos thread

    <form method="post" action="path to script">
    <input type="checkbox" id="colors[]" value="red" /> Red
    <input type="checkbox" id="colors[]" value="blue" /> Blue
    <input type="checkbox" id="colors[]" value="green" /> Green
    <input type="checkbox" id="colors[]" value="yellow" /> Yellow
    </form>

    Ok I now know how to insert this into the databse using implode() and I also know how to extract it from the database using explode()


    Now I am confrontred with the following problems

    If I do a SELECT from a table I might get a couple of rows that might look like this, let say that we have "|" as the separator

    red
    red|green|yellow
    red|green
    red|yellow
    green|yellow
    yellow|blue
    blue
    yellow
    green|yellow|blue
    red|yellow|blue etc etc

    NOw each row represent the different colors that were purchased during a single purchase.So a person can purchase one color or he can purchase many colors

    My Dilema

    Lets say I want to display all those that bought red and some other color, basically I want something like Amazon.com where they say those that bought this book also bought this one as well.

    How would I go about doing this in PHP, is it possible.

    Please help
    Didi

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your SQL, you can do your where clause like this:

    Code:
    where color like '%red%'
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THanks vinyl-junkie

    You are so helpful

    My problem now arises when I want to compare muliple layers of information.

    Another scenario where I will use the implode and explode is with a nutrition supplement planner

    take a look at the planner at this site
    http://www.wellnesssurvey.com/assessment.shtml

    Now I want to know if a person has diabetes, then what are the most common conditions associated with diabetes, so lets say we want the top 5 conditions associated with diabetes, how would I get that information

    Thanks again
    Didi

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your nutrition supplement planner have information that correlates to various medical conditions? Like for example, if you have diabetes, you may want to take Supplement A. If you have something in one table (nutrition supplements table?) that correlates to medical conditions, you can do a query something like this:

    Code:
    Where medical condition = "diabetes" and NutritionSupplement.ForCondition like '%diabetes%'
    I'm afraid I'm at a bit of a disadvantage in not knowing your database structure though. The above is just a guess on how you'd retrieve the results you're looking for.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI

    I do indeed have a supplement that I will lets say recommend for diabetes,however in the planner, we ask the visitor to indicate all symptoms that are
    giving them concern so a person could tick,

    Pregnancy
    Premenstrual Tension
    Prostatitis
    Prostate Cancer
    Psoriasis
    Rheumatism
    Scabies
    Schizophrenia
    Shingles
    Sinusitis
    SkinCancer
    SkinRash

    as conditions that are giving them concern.I would then implode them and
    insert into a database, now when I do a select I would explode.

    Now lets say I want to know the top 5 or even top 10 conditions that are also selected together with skinrash, this way as can develop a pattern and say that if a person has skinrash, then also have scabies (Just an example)
    etc etc , so I want to know how many people that have selected skinrash have also selected another condition and lets say I want to know the top 5 or even 10 other conditions that were selected with skinrash.

    Hope I am clear, sorry if I am not.

    Please help

    Didi

  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Didi,

    You're being very clear on what you want to do. Unfortunately, you're taxing my knowledge of SQL a bit beyond its limits.

    You might want to start a new thread in the MySQL forum with these questions, as that forum is more in keeping with the kind of help you're seeking, and you will probably have a better chance of getting them answered there. I would suggest while you're at it to change the subject to reflect the fact that you need query help.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  7. #7
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    will do


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •