1

I have two tables, I want to select from the first the ID of Salles for each Responsible (he may have many -> array()) .

so I want to select all the salles this responsible have, and I did this statement (which returns an empty array and I am unsure of why):

$sels = $db->prepare("SELECT salle FROM salleresp  WHERE resp = :resp");
$sels->bindParam(':resp',$rsb['matricule']);
$sels->execute();

$rss = $sels->fetchAll(PDO::FETCH_ASSOC);
$questionmarks = str_repeat("?,", count($rss)-1) . "?"; 

 $selectSalle1 = $db->prepare("SELECT * FROM salle WHERE salleId IN ($questionmarks) ");
 $selectSalle1->execute($rss);
 $showAll=$selectSalle1->fetchAll(PDO::FETCH_ASSOC);

when I do:

print_r($showAll);

it return an empty array:

array()

Any suggestions please?

1 Answer 1

1
SELECT * FROM salle WHERE salleId IN (SELECT salle FROM salleresp  WHERE resp = :resp)

or

SELECT * FROM salle left join salleresp on (salle.salleId = salleresp.salle)
WHERE resp = :resp)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.