Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to "NoelDavies" answer, here is a complete code that I managed to make working for me. In case someone comes of with the same issue:</p> <pre><code>&lt;?php try { $db = new PDO('mysql:host=localhost;dbname=sub_db;charset=UTF-8', DB_USER, DB_PASS); $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); } catch (PDOException $ex) { echo "error"; } class mysql_a { public $db; public function __construct($db) { $this-&gt;db=$db; } public function count_row(){ $count = $this-&gt;db-&gt;query('SELECT COUNT(*) FROM users')-&gt;fetch(PDO::FETCH_ASSOC); return $count['COUNT(*)']; } public function find_by_id($row) { $record = $this-&gt;db-&gt;query('SELECT * FROM users LIMIT 1 OFFSET ' . $row)-&gt;fetch(PDO::FETCH_ASSOC); return $record; } } class user { public $id; public $username; public $first_name; public $last_name; public function __construct($record){ foreach ($record as $atribute =&gt; $value) { $this-&gt;$atribute = $value; } } } $users = new mysql_a($db); for ($i = 0; $i &lt; $users-&gt;count_row(); $i++) { $user = new user($users-&gt;find_by_id($i)); echo $user-&gt;id . "&lt;br /&gt;"; echo $user-&gt;username . "&lt;br /&gt;"; echo $user-&gt;first_name . "&lt;br /&gt;"; echo $user-&gt;last_name . "&lt;hr /&gt;"; } ?&gt; </code></pre> <p>It counts rows in db and then one by one pulls them out and outputs. I'm sure there is some shorter and more elegant way, but it works fine for me now;] Thanks again "NoelDavies".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload