Jump to content
php.lv forumi

problēma


sandis_m

Recommended Posts

users

uid | name | lastname | profilepic

 

 

comments

 

sid | author | time | text

 

 

comments_likes

wid | wsid | wautors

 

 

 

SQL:

 
$whatsnew_sql = mysql_query("

SELECT  comm.*, u.uid,`name`,`lastname`,`profilepic`, coommlk.*	
FROM `comments` comm, `users` u, `comments_likes` commlk

WHERE comm.author = u.uid

ORDER BY `comm.sid`  DESC LIMIT 12
");

 

 

Rezultātā vajadzētu izvadīt komentārus un ja tabulā `comments_likes` `wid` ir vienāds ar `comments` `sid` tad vajadzēja parādīties sirsniņai. Bet nez kkas tur nav kā vajag

 

1taqhar8bfbxkmqndo5a.png

Link to comment
Share on other sites

ieteiktu tabulām kā primary_key likt id, nevis xid, jo piemēram uid būtu saīsinājums no userid, bet pie tā lauka tu griezies ar users.uid.

Sanāk, ka 2 reizes lieto user. Un vispār id lietot kā primary_key, kur tā ir viena, ir tākā nedaudz standarts.

 

Par tēmu, tev vajag LEFT JOIN un tad, ja nebūs atbilstoša comments_like ieraksta, tajā vietā būs NULL.

Link to comment
Share on other sites

Tātad, tam vajadzētu izskatīties šādi?:

 

     $whatsnew_sql = mysql_query("

       SELECT  comm.*, u.uid,`name`,`lastname`,`profilepic`
       FROM `comments` comm, `users` u

       LEFT JOIN `comments_likes`

       WHERE comm.author = u.uid

       ORDER BY `comm.sid`  DESC LIMIT 12
       ");

 

bet kkas nesanāk ;/

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...