Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySQL display/order additional information on various pages
    text
    copied!<p>In my page i have a block of content where i want to display certain additional information on the side of it. This information can be the same for several pages, but items can also be displayed on one specific item. </p> <p>I'm thinking about different approached, but all my solutions seem, in my opinion, too exhaustive or i can't imagine that there isn't a more clever solution. </p> <p>Consider the following table (column-names differ from my original database, i don't use the same name in different tables) i have for the content.</p> <p><pre><code>fe_content: +----+--------+----------+-------------------+ | id | page | pagelink | content | +----+--------+----------+-------------------+ | 1 | page 1 | page_1 | Content of page 1 | | 2 | page 2 | page_2 | Content of page 2 | | 3 | page 3 | page_3 | Content of page 3 | | 4 | page 4 | page_4 | Content of page 4 | | 5 | page 5 | page_5 | Content of page 5 | +----+--------+----------+-------------------+ </pre></code></p> <p>My approach for the additional data is something like:</p> <p><pre><code>fe_blocks: +----+---------+-------+---------+----------+--------------------+ | id | block | order | display | pagelink | content | +----+---------+-------+---------+----------+--------------------+ | 1 | block 1 | 1 | always | | Content of block 1 | | 2 | block 2 | 2 | always | | Content of block 2 | | 3 | block 3 | 1 | single | page_1 | Content of block 3 | | 4 | block 4 | 3 | always | | Content of block 4 | | 5 | block 5 | 4 | single | page_3 | Content of block 5 | +----+---------+-------+---------+----------+--------------------+ </pre></code></p> <p>So now, when i want to display the page, i use:</p> <p><pre><code> $result = mysql_query(" SELECT content FROM fe_content WHERE pagelink = '"._mysql_real_escape_string($_aGET[0])."' ") or die(mysql_error()); $show = mysql_fetch_assoc($result); echo("&lt;div&gt; ".$show['content']." &lt;/div&gt;\n\n&lt;aside&gt;\n");</p> <p>$result = mysql_query(" SELECT content FROM fe_blocks WHERE pagelink = '".mysql_real_escape_string($_aGET[0])."' or display = 'always' ORDER BY order ASC ") or die(mysql_error()); while($show = mysql_fetch_assoc($result)){ echo("&lt;p&gt;".$show['content']."&lt;/p&gt;\n"); } echo("&lt;/aside&gt;"); </pre></code></p> <p>This gives me the desired blocks, but with some snags..</p> <p>Suppose i request <code>page_1</code>, my output will be</p> <p><pre><code> &lt;div&gt; Content of page 1 &lt;/div&gt; &lt;aside&gt; &lt;p&gt;Content of block 1&lt;/p&gt; &lt;p&gt;Content of block 2&lt;/p&gt; &lt;p&gt;Content of block 3&lt;/p&gt; &lt;p&gt;Content of block 4&lt;/p&gt; &lt;/aside&gt; </pre></code></p> <p>While i want to get this instead:</p> <p><pre><code> &lt;div&gt; Content of page 1 &lt;/div&gt; &lt;aside&gt; &lt;p&gt;Content of block 3&lt;/p&gt; &lt;p&gt;Content of block 1&lt;/p&gt; &lt;p&gt;Content of block 2&lt;/p&gt; &lt;p&gt;Content of block 4&lt;/p&gt; &lt;/aside&gt; </pre></code></p> <p>my desired results take into account:</p> <ul><li><em>Importance.</em> The order of items that are displayed on a specific page should be considered more important (e.g. overrule) than the order of items that are always displayed.</li> <li><em>Almost always.</em> Perhaps some items should be displayed on almost all pages, except a few. With respect to future changes it is not convenient to insert a new row in the database with the appropriate pagelink with it for each page where the block should be displayed.</ul> <p>Anybody some thoughts on this situation?</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