trying to make a loop, cant figure it out

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kentor

    trying to make a loop, cant figure it out

    hello, im trying to make a little loop, but i cant figure it out... i
    have a string with a bunch of 1s and 0s in it: 110101010101111 010101
    .... i need to count the number of 1s divide it by 2 and make a table
    with 2 columns and then for every one, depending on its position in the
    string i need to output a word and then go to the next 1 and output a
    dif word....

    its amenities, winter activities and summer activities for cottages
    that i store in my db with 1s and 0s when its a 1 the amenitie or
    whatever exists when its a 0 then it doesent exist...

    an example of the kind of table that i need is here:


  • rich

    #2
    Re: trying to make a loop, cant figure it out


    Kentor wrote:[color=blue]
    > hello, im trying to make a little loop, but i cant figure it out... i
    > have a string with a bunch of 1s and 0s in it: 110101010101111 010101
    > ... i need to count the number of 1s divide it by 2[/color]
    use
    $string = "11010101010111 1010101";
    $numof1s=substr _count($string, '1');
    $ans = $numof1s /2;
    I can help you with this part. The other part I have to look at a
    little longer.
    and make a table[color=blue]
    > with 2 columns and then for every one, depending on its position in the
    > string i need to output a word and then go to the next 1 and output a
    > dif word....[/color]
    I[color=blue]
    >
    > its amenities, winter activities and summer activities for cottages
    > that i store in my db with 1s and 0s when its a 1 the amenitie or
    > whatever exists when its a 0 then it doesent exist...
    >
    > an example of the kind of table that i need is here:
    > http://www.chaletsauquebec.com/Fiche...?IdChalet=2011[/color]

    Comment

    • strawberry

      #3
      Re: trying to make a loop, cant figure it out



      Kentor wrote:[color=blue]
      > hello, im trying to make a little loop, but i cant figure it out... i
      > have a string with a bunch of 1s and 0s in it: 110101010101111 010101
      > ... i need to count the number of 1s divide it by 2 and make a table
      > with 2 columns and then for every one, depending on its position in the
      > string i need to output a word and then go to the next 1 and output a
      > dif word....
      >
      > its amenities, winter activities and summer activities for cottages
      > that i store in my db with 1s and 0s when its a 1 the amenitie or
      > whatever exists when its a 0 then it doesent exist...
      >
      > an example of the kind of table that i need is here:
      > http://www.chaletsauquebec.com/Fiche...?IdChalet=2011[/color]

      Comment

      • Jerry Stuckle

        #4
        Re: trying to make a loop, cant figure it out

        strawberry wrote:[color=blue]
        > http://dev.mysql.com/tech-resources/...alization.html
        >
        > Kentor wrote:
        >[color=green]
        >>hello, im trying to make a little loop, but i cant figure it out... i
        >>have a string with a bunch of 1s and 0s in it: 110101010101111 010101
        >>... i need to count the number of 1s divide it by 2 and make a table
        >>with 2 columns and then for every one, depending on its position in the
        >>string i need to output a word and then go to the next 1 and output a
        >>dif word....
        >>
        >>its amenities, winter activities and summer activities for cottages
        >>that i store in my db with 1s and 0s when its a 1 the amenitie or
        >>whatever exists when its a 0 then it doesent exist...
        >>
        >>an example of the kind of table that i need is here:
        >>http://www.chaletsauquebec.com/Fiche...?IdChalet=2011[/color]
        >
        >[/color]

        That's the hard way to do it. You have one field which contains multiple
        values, which is almost never right. Rather, have three tables.

        Cottage
        cottage_id (other info}

        Amenity
        amenity_id amenity_descrip tion

        Cottage_Amenity
        cottage_id amenity_id


        To get a list of amenities for a specific cottage, do:

        SELECT amenity_descrip tion
        FROM Amenity a, Cottage_Amenity ca
        WHERE ca.Cottage_id = $cottageed AND
        ca.amenity_id = a.amenity_id

        And google "database normalization" for more information on how to normalize
        tables correctly.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        Working...