How to interact fields from msql tables?

Asked

Viewed 69 times

0

I’m creating a book exchange page, I made two tables of wishes and mine. until the part of the logged-in user wish to find other’s books I was able to do, but I would also like the other users to have as wish the logged-in user’s books. type: I have a book A and wish a B, and another user have the B and wish an A. My select q have done so far

   SELECT b.meu,b.autor, b.genero,b.userid, b.foto
      FROM desejos AS a 
      INNER JOIN meus AS b ON
        (CONCAT('%', a.desejo,'%') LIKE CONCAT('%', b.meu,'%')or
        CONCAT('%', a.desejo,'%') LIKE CONCAT('%', b.genero,'%')or
        CONCAT('%', a.desejo,'%') LIKE CONCAT('%', b.autor,'%'))
      WHERE
        a.userid = $_SESSION[id]
          AND
        b.userid != $_SESSION[id]

tried to put "and

   CONCAT('%', b.meu,'%') LIKE (CONCAT('%', a.desejo,'%') or  
   CONCAT('%', b.genero,'%') LIKE CONCAT('%', a.desejo,'%')or
   CONCAT('%', b.autor,'%') LIKE CONCAT('%', a.desejo,'%'))

but it didn’t work. the tables inserir a descrição da imagem aqui

  • I think it is not enough to post SQL, you should show the scheme of these tables. Is Livro an entity? " My" is a relation (N to N) with this entity? " desire" is another relationship?

  • I put an image of the tables, in case the wish and mine are names of books.

  • In my opinion, you should review this template there, is there any reason why there can not be a unique identifier for a book(id)? Are you using the title to join? It’s also unclear what your goal is with this query? What exactly do you want to list? all user books, and their "wishes"?

  • books have unique identifier, only q with id n da to compare the titles. My goal with this select is to return only user books A wish, that user B wish at least one user book A.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.