Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Database & Database Programming

Database & Database Programming MySQL, Oracle, SQL, PL/SQL, ABAP, Smart Forms, and other databases and languages. A database is an organized body of related information used in many websites (including CC).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-12-2008, 10:51 AM
gogles gogles is offline
Newbie
 
Join Date: May 2008
Posts: 4
Rep Power: 0
gogles is on a distinguished road
Default MySQL syntax error and logic issue

What seems to be the problem with this syntax?

With this query i am trying to select the members who have become friends with the friends of f.uid, f.uid2 is the id of the friend. Can anyone see any flaws in the logic of my query?

I am pretty sure facebook or myspace has this feature.

$query =

"SELECT * " .
"FROM relationships r INNER JOIN members m, friends f " .
"ON r.inviter = m.id " .
"WHERE f.uid2 = ANY (SELECT r.recipient) " .
"AND f.uid = '$id'";

My tables:

create table members (
id int not null primary key auto_increment,
username varchar(40) not null,
password varchar(40) not null,
name varchar(40) not null,
location varchar(40) not null,
gender char(1) not null check gender in ('m','f'),
email varchar(40) default '',
birthday date default null,
description text default '');

create table relationships (
id int not null auto_increment,
recipient int not null references members(id),
inviter int not null,
status varchar(20) not null,
epoch date not null,
primary key (id)
);

create table friends (
id int not null auto_increment,
uid int not null,
uid2 int not null,
primary key (id)
);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-12-2008, 11:40 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Mod
 
Join Date: Jul 2006
Age: 35
Posts: 1,846
Last Blog:
Game software (GURPS)
Rep Power: 21
WingedPanther has a spectacular aura aboutWingedPanther has a spectacular aura about
Default Re: MySQL syntax error and logic issue

The biggest problem I see is you have NO conditions on how friends f is associated with the other two tables in your join. You really need at least 2 ON conditions.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-12-2008, 01:15 PM
gogles gogles is offline
Newbie
 
Join Date: May 2008
Posts: 4
Rep Power: 0
gogles is on a distinguished road
Default Re: MySQL syntax error and logic issue

$query = "SELECT * " .
"FROM relationships r " .
"JOIN members m ON r.inviter = m.id " .
"JOIN friends f ON r.recipient = f.uid2 " .
"WHERE f.uid = $id";

Hmmmm still not exactly achieve its goal.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 10:31 AM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads