information retrieval with join not as expected

They have: 461 posts

Joined: Jul 2003

i completely redid my forum script using the old one as a shell in order to cut down the file size and speed up the script.
the file size went from approx 33000 to approx 22000. the speed is much faster since i removed a lof of if/elseif lines and if they were necessary used a switch instead. the file size really shrunk from adding modularity that was really needed.

i also modified the database structure to use joins (natural joins mostly). however the joins are giving the information i want and i'm not sure why. i'm wondering if i can get explanations on why so that i can fix this (and possibly advice too since i'm sure there's a good number of people with more expereince than i that read these boards)

the following is an example from the database, what i got whehn i tried to get the main forum page. the first section is the calls made. testing it. the last is what i think it would be. the middle is what it gives.

if you would like, i can post the file and table descriptions. right now i only modified the development server. the table was modified to remove some extra database calls from the original script and some extra instances of usernames (trying to remove even more after this to add a new function for the higher user level)

sql print out:

Quote: mysql> select tid, fid, sub from threads;
+-----+-----+---------------------------+
| tid | fid | sub |
+-----+-----+---------------------------+
| 1 | 1 | point of this forum |
| 2 | 2 | Interests |
| 3 | 3 | about calling others fake |
| 4 | 3 | Saluting |
| 5 | 4 | Hey! |
| 6 | 5 | EVERYONE |
| 7 | 2 | testing guest posting |
| 9 | 2 | logging in |
| 10 | 8 | what not to wear on TLC |
| 11 | 4 | Yo |
| 12 | 4 | Just testing... |
| 13 | 1 | Test |
| 14 | 4 | Mistakes and Errors |
| 15 | 4 | dev to demo to.... |
| 16 | 2 | test |
| 17 | 4 | double checking |
+-----+-----+---------------------------+
16 rows in set (0.05 sec)

mysql> select fid, fal, title from forums;
+-----+-----+-------------------------+
| fid | fal | title |
+-----+-----+-------------------------+
| 1 | 5 | Mod Review |
| 2 | 0 | Problems/Suggestions |
| 3 | 0 | Fakes |
| 4 | 1 | General/Misc |
| 5 | 1 | Shouts |
| 6 | 1 | Arts & Crafts |
| 7 | 1 | Entertainment |
| 8 | 1 | Fashion & Style |
| 9 | 1 | Rants & Raves |
| 10 | 1 | Relationships |
| 11 | 1 | Technology |
| 12 | 1 | Vehicles |
| 13 | 3 | Adult Misc |
| 14 | 3 | Erotica |
| 15 | 3 | Sex & Adult Chat |
| 16 | 2 | Desired's Play Pen |
| 17 | 4 | Approve & Moderate |
+-----+-----+-------------------------+
17 rows in set (0.00 sec)

---------

mysql> select tid, threads.fid, fal, sub, title from threads natural join forums;
+-----+-----+-----+-------------------------+----------------------+
| tid | fid | fal | sub | title |
+-----+-----+-----+-------------------------+----------------------+
| 4 | 3 | 0 | Saluting | Fakes |
| 6 | 5 | 1 | EVERYONE | Shouts |
| 10 | 8 | 1 | what not to wear on TLC | Fashion & Style |
| 13 | 1 | 5 | Test | Mod Review |
| 16 | 2 | 0 | test | Problems/Suggestions |
| 17 | 4 | 1 | double checking | General/Misc |
+-----+-----+-----+-------------------------+----------------------+
6 rows in set (0.00 sec)

----------
mysql> select tid, threads.fid, fal, sub, title from threads natural join forums;
+-----+-----+-----+---------------------------+----------------------+
| tid | fid | fal | sub | title |
+-----+-----+-----+---------------------------+----------------------+
| 1 | 1 | 5 | point of this forum | Mod Review |
| 2 | 2 | 0 | Interests | Problems/Suggestions |
| 3 | 3 | 0 | about calling others fake | Fakes |
| 4 | 3 | 0 | Saluting | Fakes |
| 5 | 4 | 1 | Hey! | General/Misc |
| 6 | 5 | 1 | EVERYONE | Shouts |
| 7 | 2 | 0 | testing guest posting | Problems/Suggestions |
| 9 | 2 | 0 | logging in | Problems/Suggestions |
| 10 | 8 | 1 | what not to wear on TLC | Fashion & Style |
| 11 | 4 | 1 | Yo | General/Misc |
| 12 | 4 | 1 | Just testing... | General/Misc |
| 13 | 1 | 5 | Test | Mod Review |
| 14 | 4 | 1 | Mistakes and Errors | General/Misc |
| 15 | 4 | 1 | dev to demo to.... | General/Misc |
| 16 | 2 | 0 | test | Problems/Suggestions |
| 17 | 4 | 1 | double checking | General/Misc |
+-----+-----+-----+---------------------------+----------------------+
17 rows in set (0.00 sec)

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

s0da's picture

He has: 157 posts

Joined: Mar 2004

er.. what is the question? Sad

They have: 461 posts

Joined: Jul 2003

help me understand why it's getting

Quote: mysql> select tid, threads.fid, fal, sub, title from threads natural join forums;
+-----+-----+-----+-------------------------+----------------------+
| tid | fid | fal | sub | title |
+-----+-----+-----+-------------------------+----------------------+
| 4 | 3 | 0 | Saluting | Fakes |
| 6 | 5 | 1 | EVERYONE | Shouts |
| 10 | 8 | 1 | what not to wear on TLC | Fashion & Style |
| 13 | 1 | 5 | Test | Mod Review |
| 16 | 2 | 0 | test | Problems/Suggestions |
| 17 | 4 | 1 | double checking | General/Misc |
+-----+-----+-----+-------------------------+----------------------+
6 rows in set (0.00 sec)

instead of

Quote: mysql> select tid, threads.fid, fal, sub, title from threads natural join forums;
+-----+-----+-----+---------------------------+----------------------+
| tid | fid | fal | sub | title |
+-----+-----+-----+---------------------------+----------------------+
| 1 | 1 | 5 | point of this forum | Mod Review |
| 2 | 2 | 0 | Interests | Problems/Suggestions |
| 3 | 3 | 0 | about calling others fake | Fakes |
| 4 | 3 | 0 | Saluting | Fakes |
| 5 | 4 | 1 | Hey! | General/Misc |
| 6 | 5 | 1 | EVERYONE | Shouts |
| 7 | 2 | 0 | testing guest posting | Problems/Suggestions |
| 9 | 2 | 0 | logging in | Problems/Suggestions |
| 10 | 8 | 1 | what not to wear on TLC | Fashion & Style |
| 11 | 4 | 1 | Yo | General/Misc |
| 12 | 4 | 1 | Just testing... | General/Misc |
| 13 | 1 | 5 | Test | Mod Review |
| 14 | 4 | 1 | Mistakes and Errors | General/Misc |
| 15 | 4 | 1 | dev to demo to.... | General/Misc |
| 16 | 2 | 0 | test | Problems/Suggestions |
| 17 | 4 | 1 | double checking | General/Misc |
+-----+-----+-----+---------------------------+----------------------+
17 rows in set (0.00 sec)

so that i can get it to that second one

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

druagord's picture

He has: 335 posts

Joined: May 2003

shouldn't the fields from the forum table be called like this forums.title,forums.fal

druagord's picture

He has: 335 posts

Joined: May 2003

Also since you only need to join on fid this query should be better

SELECT tid, threads.fid, forums.fal, sub, forums.title FROM threads LEFT JOIN forums ON threads.fid=forums.fid;
'

IF , ELSE , WHILE isn't that what life is all about

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.