Jump to content

[SOLVED] Database problems. . .


czukoman20

Recommended Posts

First off. what type of variable would i use in a table for a database in mysql that can make a list.

so that later on when i refer to it in php. then it will bring up a list of names.

 

What i want to use this for is a user has a favorites column in the database. and when they click add user to favorites... it adds a name to the list in the database. or like an ID number. just so we can keep track of what users like what other users have.

 

then after that is in the database. i would like to be able to refer to that list in a php document that lists all the users in the list.

 

it sounds like a difficult process. but i just need a basic template as to how this works.

i have no code written yet. or a datatable set up. so its up to you. please tell me if this is clear enough.

 

it would be greatly appreciated ;)

Link to comment
Share on other sites

Something like a buddy list? You don't actually store a list in one row, but have multiple rows. Create a table (buddies), with two fields (userid,buddyid). Then, everytime a user adds a buddy simply add a new record with there id and the buddies id. eg;

 

INSERT INTO buddies (userid,buddyid) VALUES ('thorpe','bob');
INSERT INTO buddies (userid,buddyid) VALUES ('thorpe','foo');
INSERT INTO buddies (userid,buddyid) VALUES ('thorpe','bar');

 

This would add three buddies to my list of buddies. Now, to retrieve a list of my buddies, simply run...

 

SELECT buddyid FROM buddies WHERE userid = 'thorpe';

 

hope this helps.

Link to comment
Share on other sites

Can you explain that a bit more. Like exactly what variables to use in the table when setting it up. and where to put these actual tables. because its

and how does this go for more that 1 person doing this. will two people be in this datatable. im not getting as to how this works.

Link to comment
Share on other sites

Read this post here as well, its exactly the same thing. And yes, of course you can have more than one user in the same table. Each record added relates a user with there buddy. Its quite simple.

 

In the link I just gave there is an example of a add job link. Yours would be exactly the same but add buddy.

Link to comment
Share on other sites

ok .... so now i have run into another issue

INSERT INTO [u]buddies[/u] (userid,buddyid) VALUES ('thorpe','bob');

 

 

The buddies is the datatable right.

 

Well i have a datatable setup like so

 

http://www.czartgaming.com/testpages/help/database1.jpg

http://www.czartgaming.com/testpages/help/database2.jpg

 

 

Can you have me figure out how to guide the insert function to my database. 

and how i would have to setup the actual area where i put the information?

Link to comment
Share on other sites

ok .... so now i have run into another issue

Code:

 

INSERT INTO buddies (userid,buddyid) VALUES ('thorpe','bob');

 

 

oy i h8 bein a nuv.. ok well with that piece of code it directs the information to the buddies datatable in the mysql database

 

How do i make it go into a sub-table. like buddies/buddyinfoo

 

like the INSERT INTO buddies _______ (userid,buddyid) VALUES ('thorpe','bob');

 

im just confused as to pointing it where to go in the mysql db

Link to comment
Share on other sites

You need to create a table called buddies.  Use the following SQL or use phpMyAdmin:

 CREATE TABLE `dowmodsc_pico`.`buddies` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`userID` INT NOT NULL ,
`buddyID` INT NOT NULL
) ENGINE = InnoDB 

 

You can then insert buddies using the following SQL query:

INSERT INTO buddies (userID,buddyID) VALUES ('1','2');

Where userID and buddyID relate to the relevant userid from the users table.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.