Note that there are some explanatory texts on larger screens.

plurals
  1. POParallel MySQL queries for HTML table - WHILE(x or y)?
    text
    copied!<p>I'm trying to create a table using PHP. What I need is a table with two columns.</p> <p>So I have an SQL table with 4 fields - primary key id, language, word and definition. The language for each is either Arabic or Russian.</p> <p>I want a table that does the following:</p> <pre><code>| defintion | |____________________| | | | rus1 | arab1 | | rus2 | arab2 | | rus3 | arab3 | | rus4 | | </code></pre> <p>So it divides the list by English word, creates a for each English word, then lists Russian equivalents in the left column and Arabic in the right. However there are often not the same number for both. What I am doing right now is running a WHILE loop in a WHILE loop. The outer loop is running fine but I think I am doing the inner loop wrong. Here is the bulk of the code:</p> <pre><code>$definitions=mysql_query("SELECT DISTINCT definition FROM words") WHILE($row=mysql_fetch_array($definitions) { ECHO '&lt;tr&gt;&lt;th colspan="2"&gt;' . $row['definition'] . '&lt;/th&gt;&lt;/tr&gt;'; $russian="SELECT * FROM words WHERE language='Russian' AND definition='".$row['definition']."'"; $arabic="SELECT * FROM words WHERE language='Arabic' AND definition='".$row['definition']."'"; WHILE($rus=mysql_fetch_array($russian) or $arb=mysql_fetch_array($arabic)) { ECHO '&lt;tr&gt;&lt;td&gt;'.$rus['word'].'&lt;/td&gt;&lt;td&gt;'.$arb['word'].'&lt;/td&gt;&lt;/tr&gt;'; } } </code></pre> <p>Sadly I am getting soemthing like this:</p> <pre><code>| defintion | |____________________| | | | rus1 | | | rus2 | | | rus3 | | | rus4 | | | | arab1 | | | arab2 | | | arab3 | </code></pre> <p>Not sure what other way I can do this? I tried changing the or to || thinking the different precedence would cause another outcome, but then I get ONLY the Russian column.</p> <p>I'm out of ideas, you guys are my only hope!</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