Computing.Net > Forums > Web Development > explode array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

explode array

Reply to Message Icon

Name: BigShow
Date: October 24, 2008 at 18:18:16 Pacific
OS: xp
CPU/Ram: pentium 4
Product: dell
Comment:

Hey guys,

This one seems simple but I can't wrap my brain around it. Basically I have a table in my DB that cloects id's. When it first starts it is empty but when someone adds an id it needs to append to the list in there. I figure to seperate the list with commas so I can have a way of dividing it when I need to. So basically I need to take whats in there, add a comma and id to it then put it back. I may start the table off with a ,1 just so I have a starting point. I am thinking I need to use explode to turn it into an array, array_push to put the "," and "3(number)" in the array then put it back together and update the field. Think of it along the lines of each person having an id and adding a friend to your profile (as within a social network). Any help would be appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: October 24, 2008 at 20:38:31 Pacific
Reply:

I would suggest you scrap that idea entirely. The strength of using a "relational" database is in using different tables with related records.

In this instance you have usr table. Each record in that table has an ID, correct? So you should then create a second table such as friends. That table would only need two columns: user_id & friend_id. You can then have a many-to-one relationship. A user can have many records in the firend table that point back to the record in the user table.

You can then get very complex datasets from the database with a single query. For example you could get a list of all fiends for a single user with one query. With the method above you would first have to query for the user, then extract the data to then query for the friends.

Michael J


0

Response Number 2
Name: BigShow
Date: October 26, 2008 at 11:39:07 Pacific
Reply:

He Michael, I actually figured it out but your are right. In fact i have a request table that has a too and from column in it that gets deleted once someone says approve or deny, I can just use tha with different code, good idea.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: explode array

Help with Checkboxes and array PHP www.computing.net/answers/webdevel/help-with-checkboxes-and-array-php/2568.html

getting my data working as an array www.computing.net/answers/webdevel/getting-my-data-working-as-an-array/2461.html

PHP File read/write?????? www.computing.net/answers/webdevel/php-file-readwrite/1298.html