472,796 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

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: 110101010101111010101
.... 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

Jun 4 '06 #1
3 1749

Kentor wrote:
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: 110101010101111010101
... i need to count the number of 1s divide it by 2 use
$string = "110101010101111010101";
$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 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.... I
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


Jun 4 '06 #2
http://dev.mysql.com/tech-resources/...alization.html

Kentor wrote:
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: 110101010101111010101
... 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


Jun 4 '06 #3
strawberry wrote:
http://dev.mysql.com/tech-resources/...alization.html

Kentor wrote:
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: 110101010101111010101
... 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



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_description

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

SELECT amenity_description
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.
js*******@attglobal.net
==================
Jun 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ben Hallert | last post by:
Hi there, I haven't done a lot of Javascript programming, so I'm not having great luck debugging something I put together, and I was hoping someone here could give it a quick lookover and maybe...
3
by: ehaffey | last post by:
Hi, Im trying to get a VB.NET program to create a shared folder. I can make the folder but I cant figure out how to make it as a shared folder. Also I will want to set the permissions on the...
18
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
2
by: g35rider | last post by:
Hi, I have the following code that is giving this error, I cant simplify the code, I was just testing some theory for something we are doing and was getting an issue here. Please someone point out...
4
by: NancyJ | last post by:
Currently we have a database with a main table containing 3 million records - we want to increase that to 10 million but thats not a possibility at the moment. Nearly all 3 million records are...
3
by: phwashington | last post by:
I am new to C++ and have a data file I want to read, which was stored in binary. I have looked at the data with a hex editor and it appears to be correct. Whenever I try to read it though as an...
2
by: gdarian216 | last post by:
I am tring to write a program that will take a string of text input and correct the spacing and capitalization. I have been able to get it to except the string by using getline. I know that the...
3
by: eDaddi | last post by:
I can't figure out why I cant get this simple loop to work. I'm using it to validate a form. I thought I could put the required field names in an array, loop through the array and have the it check...
5
by: Daten | last post by:
I have a loop that looks like this int i; for (i = 0; i < FriendsArray.Count; i++) { MessageBox.Show("Im in the loop " + key);
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.