Note that there are some explanatory texts on larger screens.

plurals
  1. POWhile loop into a switch in PHP?
    primarykey
    data
    text
    <p>I am trying to make a website in different languages and I retrieve this information from a database. For now I have two languages in there: English and Dutch.</p> <p>What I would like to do is getting all the language possibilities and put this into a switch. So if people will click on for example this link: index.php?page=NL they will get the Dutch translation of the page.</p> <p>So this is the code that I am using. It works so far but it shows I think the language option and the default option. Because when I remove default I only get the code ones.</p> <pre><code> &lt;div id="content"&gt; &lt;?php //Retrieve languages $querySwitchLang = "SELECT * FROM languages"; $resultSwitchLang = mysql_query($querySwitchLang); ?&gt; &lt;?php while($rowSwitchLang = mysql_fetch_array($resultSwitchLang)){ switch($page){ case $rowSwitchLang['langCode']:include('page.php');break; default: include('pageDefault.php'); break; } } ?&gt; &lt;/div&gt; </code></pre> <p>So actually I wanted to have it like this because now it runs the switch statements as many times as there are languages I think:</p> <pre><code> &lt;div id="content"&gt; &lt;?php //Retrieve languages $querySwitchLang = "SELECT * FROM languages"; $resultSwitchLang = mysql_query($querySwitchLang); ?&gt; &lt;?php include('functions.php'); switch($page){ while($rowSwitchLang = mysql_fetch_array($resultSwitchLang)){ case $rowSwitchLang['langCode']:include('page.php');break; } default: include('pageDefault.php'); break; } ?&gt; &lt;/div&gt; </code></pre> <p>But this doesn't work because then I will get this error:</p> <pre><code>Parse error: syntax error, unexpected 'while' (T_WHILE), expecting case (T_CASE) or default (T_DEFAULT) or '}' in C:\wamp\www\glimpler\index.php on line 6 </code></pre> <p>I can't realy figure out how to solve this problem.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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