Sunamena Posted May 6, 2017 Share Posted May 6, 2017 Hello everyone, this is what i want to achieve: When someone looks in his or her Inbox, (s)he can see all messages directer to him or her. This is my code (the part which is needed for my question ;)): $sql = "SELECT * FROM berichten WHERE voor = :voor ORDER BY berichtid"; $stmt = $db -> prepare($sql); $stmt -> bindParam(':voor', $voor, PDO::PARAM_INT); $voor = $_SESSION["userID"]; $stmt -> execute(); $result = $stmt -> fetch(PDO::FETCH_NUM); $numberInResult = count($result)-1; // THIS IS TO CHECK MY RESULTS print_r($result); echo "<br><br><br>"; echo "<br><br><br>"; echo $numberInResult; // Number in results is 5. (Which is incorrect, the test person has 7 messages. The table does have 6 rows, which is why the result is 5, atleast i think. for ($i = 0; $i < $numberInResult; $i++) { ?> <div class="inbox-row"> <div class="inbox-data"> <?php echo $result["1"]; ?> </div><!-- --><div class="inbox-data"> <?php echo $result["2"]; ?> </div><!-- --><div class="inbox-data"> <?php echo $result["5"]; ?> </div><!-- --><div class="inbox-data"> Verwijderen </div> </div> // And i get to see 5 times the first message send to me. // Which should be 7 different messages send to me. // I also tried to use <?php echo $result["1"][$i]; ?> , this resulted in only having a single part of the String (which was something i learned thanks to this =D) So I would like to know the following: How to SELECT ALL the messages IN that table that are directed at ME? I want multiple columns selected, and echo'ed. I would love to thank anyone who answers this question in Advance =D Link to comment Share on other sites More sharing options...
niche Posted May 6, 2017 Share Posted May 6, 2017 (edited) You probably have a problem when you bindParam especially when you expect a different row count. Is :voor really an INT? http://php.net/manual/en/pdostatement.bindparam.php Also, you need to use try/catch for errors. Edited May 6, 2017 by niche Link to comment Share on other sites More sharing options...
dsonesuk Posted May 6, 2017 Share Posted May 6, 2017 (edited) You are binding the variable value of $voor BEFORE the value of $voor is retrieved from session. Edited May 6, 2017 by dsonesuk Link to comment Share on other sites More sharing options...
Sunamena Posted May 6, 2017 Author Share Posted May 6, 2017 :voor is an INT. I do use Try and Catch, but i left that out of the code (i wanted to focus on the part that did not work). =D And dsonesuk: Yes i did, i did it once to much =D And the previous one had to be a fetchAll =D This problem has been solved. Thanks all =D Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now