MySQL / PHP dating site
- Started
- Last post
- 40 Responses
- juhls
Hey,
I'm working on a dating site for some practice.
Currently I just have a registration form, so I will have a bunch of questions today and tomorrow about the login stuff etc.
For now though, I have a table that contains all of the fields for the registration form. First name, last name, and so on. This goes into a table called "clients". It includes a column with a client id (auto increment).
In the form, I have a field that asks them for their interests, separated by a comma. It's going to be inserted into a different table called "client_interests" with columns for interest_id (auto increment), client id (same as "client" table), and interests column for the interest name itself.
How can I implode the interests properly and make sure they contain the same client ID in both tables?
Thanks.
- ETM0
If you allow people to type in their interests freeform, matching logic could be more difficult. Adding in multiple terms for similar activities, people's inability to spell etc, there are a lot of variables. A group of say 10 drop downs prepopulated with common activities may work better. Depends on how broad or detailed you want to have the answers be at that stage.
- juhls0
Hmm...I may do it that way. I want to match the interests on a separate page where the user has to login first.
- acescence0
one table stores users,
one table stores interests (each interest is a row),
a third table stores the relationships between users and interests- also known as many-to-many relationshipsacescence
- http://en.wikipedia.…)acescence
- don't forget to add foriegn keys and manage the indexes properlysection_014
- mikotondria30
ace is right, you'll arrive at the same conclusions either by diligent book-learnin' or some nasty curves in your development processes - soon it'll really become second nature as to how to organise data like this...just over-name everything as if it needs to be understood by a complete idiot (this will be you when you come back to the project in 6 months times)..
- juhls0
I'm trying to get more info about how to INSERT the data correctly with PHP. So that the client_id matches in both tables. I'm not sure if a left join or any kind of join is necessary for this.
- acescence0
joins are for selecting data, no joins involved here. when you insert the user into the table, check mysql_insert_id after to get the id it was given.
- mikotondria30
Do the insert query for the user data, then make the very next thing you do getting the last_insert_id for that record, then just INSERT INTO the other table, SET client_id = the last_insert_id you just got.
Last_insert_id (http://php.net/manual/en/functi... gets the most recently generated index where you used auto_increment...
Lots of googled stuff on it... best of luck
- SoulFly0
I want to sign up, how much you'll charge monthly fee?
I'm assuming it will be free within the first 6 months until it really kicks off correct?
- ukit0
A dating site for QBNers...I like it
- In this sausage factory??ETM
- http://www.prisondat…drgss
- It's not real.juhls
- prisondate.se? its swedish. They're planing to have one in norway, state-founded
http://www.dagbladet…drgss
- juhls0
This is what I have so far
$insert_id = mysqli_insert_id($oConn);
$query2 = "INSERT INTO client_interests(client_id, interest) ". "VALUES ('$insert_id', ')";
$result2 = mysqli_query($oConn, $query2) or die('Error querying database.');
In the $query2 area...how can I write it out (simplest way) so that the interests (which the user has written out with commas in-between) is exploded into multiple rows?
Something like this?
$interest_list = implode(',', $interests);
And/or an array?
- maybe a for loop? for($i = 0; $i <= strlen($string); $i++){
or is it simple...juhls
- maybe a for loop? for($i = 0; $i <= strlen($string); $i++){
- drgss0
explode the string?
$interests_array = array_map('trim', explode(',', $interests_string));
foreach ($interests_array as $interest) {
...
}- <- thismikotondria3
- do you put the INSERT statement in there?juhls
- the two last lines
$query2 = ... "VALUES ('$insert_id', '$interest')";
$result2 ...drgss - got it, thanksjuhls
- comicsans0
This is not going to end well.
- < doucheETM
- no, I'd say he's spot on. I believe the OP is out of his league doing a site this complicated.section_014
- Its for fucking practice. Not a client. READ the thread.ETM
- comicsans0
^ Someone who knows he doesn't know what he is doing being advised by people who don't know they don't know what they are doing.
My hourly rate for repairing systems like this is triple my normal rate
- Orbit0
^ Someone who doesn't know what the thread is about, thinking he knows what the thread is about, and berating people who do know what the thread is about and are trying to help out.
My hourly rate for correcting mistakes like this is triple my normal rate.
- acescence0
i know the answer, but i think i'll keep it to myself. good luck!
- skt0
$600 a day.
- moth0
Plenty of example data models out there Juhls:
http://www.databasedev.co.uk/dat…
- moth0
And on naming;
http://www.xaprb.com/blog/2008/1…