Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to display the result of a mysql query without looping in php?
    primarykey
    data
    text
    <p><strong>Is it possible to use an array holding the result of a mysql query and displaying it by incrementing the array index counter?</strong></p> <p>I have this code that allows a number input from 6 to 11 and generates 2 tables dividing the number equally if possible.It generates incremented team names (ex. team 1, team2, ...). I tried using a loop in displaying the real team names from my database but it loops the generation of tables also and creates so many tables.please help.</p> <pre><code>&lt;?php $count = count($result); $team = $count; $teamctr = 1; if ($team &gt; 5 &amp;&amp; $team &lt;= 11){ $table = 2; $tblctr = 1; $r1ctr = 0; $r2ctr = 0; if ($team == 6){ $row1 = 3; $row2 = 3; } else if ($team == 7){ $row1 = 3; $row2 = 4; } else if ($team == 8){ $row1 = 4; $row2 = 4; } else if ($team == 9){ $row1 = 4; $row2 = 5; } else if ($team == 10){ $row1 = 5; $row2 = 5; } else if ($team == 11){ $row1 = 5; $row2 = 6; } while($tblctr &lt;= $table){$i = 0; echo "Number of Teams: ".$team; ?&gt;&lt;br&gt;&lt;?php echo "Group Into: ".$table; ?&gt;&lt;br&gt;&lt;?php ?&gt; &lt;table border="1" align="center" width="30%"&gt; &lt;tr&gt; &lt;th width="80%" align="center"&gt;Group &amp;nbsp &lt;?php echo $tblctr; ?&gt;&lt;/th&gt; &lt;th width="10%" align="center"&gt;W&lt;/th&gt; &lt;th width="10%" align="center"&gt;L&lt;/th&gt; &lt;/tr&gt; &lt;?php if($tblctr = 1){ while($r1ctr &lt; $row1){ ?&gt; &lt;tr&gt; &lt;td&gt;Team &amp;nbsp &lt;?php echo $teamctr ?&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="score" maxlength="6" size="6" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="score" maxlength="6" size="6" /&gt;&lt;/td&gt; &lt;?php $r1ctr++; $teamctr++; } echo ""; ?&gt;&lt;br&gt;&lt;?php } if($tblctr = 2){ ?&gt; &lt;table border="1" align="center" width="30%"&gt; &lt;tr&gt; &lt;th width="80%" align="center"&gt;Group &amp;nbsp &lt;?php echo $tblctr; ?&gt;&lt;/th&gt; &lt;th width="10%" align="center"&gt;W&lt;/th&gt; &lt;th width="10%" align="center"&gt;L&lt;/th&gt; &lt;/tr&gt; &lt;?php while($r2ctr &lt; $row2){ ?&gt; &lt;tr&gt; &lt;td&gt;Team &amp;nbsp &lt;?php echo $teamctr ?&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="score" maxlength="6" size="6" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="score" maxlength="6" size="6" /&gt;&lt;/td&gt; &lt;?php $r2ctr++; $teamctr++; } echo ""; ?&gt;&lt;br&gt;&lt;?php } else{ echo "Done IF"; } $tblctr++; } } </code></pre> <p>How can I use this query to display the team name from my database?</p> <pre><code>$query = "SELECT * From tbl_teams"; $result = mysql_query($query); if($result) { $i = 0; while ($row = mysql_fetch_array($result)) { $id[$i] = $row['team_name']; echo $id[$i]; } } </code></pre>
    singulars
    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