Note that there are some explanatory texts on larger screens.

plurals
  1. POPage displaying class is not behaving well
    text
    copied!<p>For a simple cms I am working on i built a class to display articles inside defined pages.</p> <p>What i want for example: index.php?page=1 it will display all articles matching page_id 1.</p> <p>So far it works, it will display all articles with page_id 1, but for page_id 2 it does not work. A record with page_id 2 exists at the db table.</p> <p>Class:</p> <pre><code> include_once('./includes/config.php'); class Content { public $id; public $page_id; public $title; public $content; public $position; var $conn; function Content() { $this-&gt;conn = mysql_connect(Config::DB_HOST, Config::DB_USER, Config::DB_PASS); mysql_select_db(Config::DB_NAME, $this-&gt;conn); } function disp_page_articles($page) { $sql = " SELECT id , page_id , title , content , date , position FROM articles WHERE page_id = $page ORDER BY id , position"; $result = mysql_query($sql, $this-&gt;conn) or die(mysql_error()); if(!$result){ return array(); } while($article = mysql_fetch_assoc($result)){ $content .= ' &lt;div class="blok"&gt; &lt;h2&gt; &lt;/br&gt; '.$article['title'].'&lt;/h2&gt; &lt;/br&gt; '.$article['content'].' &lt;/br&gt; '.$article['date'].' &lt;/div&gt; '; } return $content; } } </code></pre> <p>Running the class:</p> <pre><code>include("classes/content.class.php"); $content = ""; $content = new Content(); $page = $_GET['page']; echo $content-&gt;disp_page_articles($page); echo "&lt;p&gt;Page ID: ". $_GET['page']."&lt;/p&gt;"; </code></pre> <p>Did i forget something here?</p>
 

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