Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
PHP - PDO Only Returns One Row
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Berk" data-source="post: 436880" data-attributes="member: 63611"><p>Hey, everyone. It's me again.</p><p></p><p>So I'm doing abit of OOP here, and I have a bit of problem, where PDO returns only 1 row instead all rows, my code for example is below. This happens for every function, it only returns one row.</p><p>[PHP]</p><p>public static function getBans()</p><p> {</p><p> global $conn; </p><p> $stmt = $conn->prepare("SELECT * FROM bans");</p><p> $stmt->execute();</p><p> $stmt = $stmt->fetchAll();</p><p> foreach($stmt as $ban)</p><p> {</p><p> return "<tr></p><p> <th scope='row'>".$ban['id']."</th></p><p> <td>".self::userDataFromId($ban['user_id'],'username')."</td></p><p> <td>".$ban['ip']."</td></p><p> <td>".$ban['machine_id']."</td></p><p> <td>".self::userDataFromId($ban['user_staff_id'],'username')."</td></p><p> <td>".date('Y-m-d H:s:i',$ban['timestamp'])."</td></p><p> <td>".date('Y-m-d H:s:i',$ban['ban_expire'])."</td></p><p> <td>".$ban['ban_reason']."</td></p><p> <td>".$ban['type']."</td></p><p> <td><a href='editban?id=".$ban['id']."'><i class='fa fa-pencil'></i></a>&nbsp; <a id='delete' href='#' data-id='".$ban['id']."'><i class='fa fa-trash'></i></td></p><p> </tr>";</p><p> }</p><p> }</p><p>public static function getFilters()</p><p> {</p><p> global $conn;</p><p> $stmt = $conn->prepare("SELECT * FROM `hk`.`wordfilter` LIMIT 0, 1000");</p><p> $stmt->execute();</p><p> $stmt = $stmt->fetchAll();</p><p> foreach($stmt as $filter)</p><p> {</p><p> return "<tr id='". $filter['id']. "'></p><p> <td>".$filter['key']."</td></p><p> <td>".$filter['replacement']."</td></p><p> <td><a href='editfilter?key=".$filter['key']."' id='edit' ><i class='fa fa-pencil'></i></a></td></p><p></p><p> ";</p><p> }</p><p> }</p><p>[/PHP]</p><p>I don't really know what I'm doing - <span style="font-size: 9px">i wish i did. </span><span style="font-size: 12px">anyway, I hope y'all can help me.</span></p><p><span style="font-size: 12px"></span></p><p><span style="font-size: 12px">Thanks.</span></p><p><span style="font-size: 12px"></span></p></blockquote><p></p>
[QUOTE="Berk, post: 436880, member: 63611"] Hey, everyone. It's me again. So I'm doing abit of OOP here, and I have a bit of problem, where PDO returns only 1 row instead all rows, my code for example is below. This happens for every function, it only returns one row. [PHP] public static function getBans() { global $conn; $stmt = $conn->prepare("SELECT * FROM bans"); $stmt->execute(); $stmt = $stmt->fetchAll(); foreach($stmt as $ban) { return "<tr> <th scope='row'>".$ban['id']."</th> <td>".self::userDataFromId($ban['user_id'],'username')."</td> <td>".$ban['ip']."</td> <td>".$ban['machine_id']."</td> <td>".self::userDataFromId($ban['user_staff_id'],'username')."</td> <td>".date('Y-m-d H:s:i',$ban['timestamp'])."</td> <td>".date('Y-m-d H:s:i',$ban['ban_expire'])."</td> <td>".$ban['ban_reason']."</td> <td>".$ban['type']."</td> <td><a href='editban?id=".$ban['id']."'><i class='fa fa-pencil'></i></a> <a id='delete' href='#' data-id='".$ban['id']."'><i class='fa fa-trash'></i></td> </tr>"; } } public static function getFilters() { global $conn; $stmt = $conn->prepare("SELECT * FROM `hk`.`wordfilter` LIMIT 0, 1000"); $stmt->execute(); $stmt = $stmt->fetchAll(); foreach($stmt as $filter) { return "<tr id='". $filter['id']. "'> <td>".$filter['key']."</td> <td>".$filter['replacement']."</td> <td><a href='editfilter?key=".$filter['key']."' id='edit' ><i class='fa fa-pencil'></i></a></td> "; } } [/PHP] I don't really know what I'm doing - [SIZE=1]i wish i did. [/SIZE][SIZE=3]anyway, I hope y'all can help me. Thanks. [/SIZE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
PHP - PDO Only Returns One Row
Top