473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1781

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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.