Note that there are some explanatory texts on larger screens.

plurals
  1. POPage Class Guidance
    primarykey
    data
    text
    <p>I'm trying to figure out how to query a database and output the results in oop on multiple pages.</p> <p>The pages will have different queries and number of queries and some will have similar layouts whilst others will be completely different.</p> <p>Is this the right direction to go in to have classes for each page that hold the required sql fields and possibly the html for outputting the data? Or would a more experienced oop designer do it differently?</p> <p>e.g (apologies for the terrible pseudo code):</p> <pre><code>abstract class Page(){} class SearchPage extends Page() { private $sql; function output(){}; } class ProfilePage extends Page() { private $sql; private $sql2; function output(){}; ← dynamic method that can output both sql and sql2?? } class DatebaseFetch() { __construct($sql) { $this-&gt;$sql=$sql; } function results() { ...get db results...; return $results;} } } class PageFactory() { function getPage($page) { return new $page.Page(); } } $page=PageFactory::getPage($_SERVER['PHP_SELF']); $query=$page-&gt;sql; $db=new DatabaseFetch($query); $results=$db-&gt;results(); $page-&gt;output($results); </code></pre> <p>The whole point of the code is to get the oop equivalent of this procedural code:</p> <pre><code>Search Page: $db=new PDO("mysql:host=localhost;dbname=test;","test","test"); $db-&gt;query("select search items from table"); while($row=$db-&gt;fetch(PDO::FETCH_ASSOC)){ echo &lt;html&gt;....; } Profile Page: $db=new PDO("mysql:host=localhost;dbname=test;","test","test"); $db-&gt;query("select profile items from table"); while($row=$db-&gt;fetch(PDO::FETCH_ASSOC)){ echo &lt;html&gt;....; } </code></pre>
    singulars
    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.
 

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