Jump to content
php.lv forumi

gribās kautkā ar distinct bet nesanāk


Pentiums

Recommended Posts

Labrīt! icon1.gif

 

Ir tabula `friendship` [id|friend|owner] (Kas ar ko ir draugs)

Ir tabula `friends` [id|name|surname|utt...] (Pašu lietotāju tabula)

 

Gribas izvilkt tos kas nav mani draugi, mēģināju šādi:

 

SELECT friends.name, friends.surname, friends.bday_y, friends.bday_m, friends.bday_d, friends.nick, friends.photo, friends.city, friends.id, friendship.friend friendship_id FROM friends LEFT JOIN friendship ON friendship.friend=friends.id
WHERE friendship.owner != '".$myinfo['id']."' AND friendship.friend != '".$myinfo['id']."'
ORDER BY RAND() LIMIT 4

 

Izvelkās tie kas nesatur manu id `friendship.friend` un `friendship.owner` laukā, bet ir taču arī mani draugi draugos ar citiem lietotājiem, tātad viņi tomēr izvelkas!!

 

Kāds var palīdzēt izlabot šo lietu? Un kādi ieteikumi? Vajag taisīt vel kādu citu tabulu klāt, vai kādu lauku?

 

Paldies jau iepriekš!

Link to comment
Share on other sites

draugu draugi ir visparastakais koks. Ja tu gribi izvilkt ne-draugus, tad tevvispirms jauzraksta procedura/skats/cache tabula, kura satures visus draugus un dr-draugus rekursiva un tikai tad vari taisit not-exists.

 

Var protams to visu uzreiz rekursivi taisit, bet tas bus ljoti darbietilpigs process - izet cauri katrai "nodei" un to child ierakstiem...

 

Atrakais variants updeitot string lauku katram lietotajam, kadi tad ir vinjam draugu un dr-draugu ID. ta nebus jamekle pa koku, bet pa ljoti garu stringu. bet tas bus atrak.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...