473,738 Members | 3,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
http://www.chaletsauquebec.com/Fiche...?IdChalet=2011

Jun 4 '06 #1
3 1808

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: 110101010101111 010101
... i need to count the number of 1s divide it by 2 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 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: 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


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



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

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

Similar topics

3
1792
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 see the obvious mistake I'm making. My challenge is, I've been asked to make a change to an internal tool. It has a screen with a tree control and a series of buttons at the top. The buttons at the top control which form is submitted, and are
3
5446
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 folder and on the share. How can I do this using VB.NET code?
18
3396
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 relies on subscrption fees. Sessions ID's are matched between the browser and the server. So a users can login with same username and password and those sessions are tracked individually. Some suggest create table fields with the session ID...
2
7377
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 whats wrong with my code. class MsgData { char* data;
4
4102
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 deleted and replaced every day - all through the day - currently we're handling this by having 2 sets of tables - 1 for inserting, 1 for searching. A block of records (10k - 1 million) (distinguished by a client identifier field) happen on the...
3
3237
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 integer it returns the 8bit integer values. I can convert these to hex and they match up with what I am seeing in the data file. I guess what I need to do somehow buffer these inputs and then read them as floats, but I am not sure how to do...
2
1538
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 easest way to do it would be to make everything lowercase then make loop to look for whitespace and make sure there is only one space between words, commas, and periods. I then would need another loop to make every letter after a period capital and the...
3
1613
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 each field. My Firebug error states that 'document.user_reg.check' is invalid. I figure it should read as 'document.user.c_fname.value' for example. var check=new...
5
1303
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
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.