Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay result from database in two columns
    text
    copied!<p>EDIT: This is what I am trying to achieve: <a href="http://i.imgur.com/KE9xx.png" rel="nofollow">http://i.imgur.com/KE9xx.png</a></p> <p>I am trying to display the results from my database in two columns. I'm a bit new to PHP so I haven't the slightest clue on how to do this. Can anybody help me with this? Thanks in advance.</p> <p>Here is my current code:</p> <pre><code>include('connect.db.php'); // get the records from the database if ($result = $mysqli-&gt;query("SELECT * FROM todo ORDER BY id")) { // display records if there are records to display if ($result-&gt;num_rows &gt; 0) { // display records in a table echo "&lt;table width='415' cellpadding='0' cellspacing='0'&gt;"; // set table headers echo "&lt;tr&gt;&lt;td&gt;&lt;img src='media/title_projectname.png' alt='Project Name' /&gt;&lt;/td&gt; &lt;td&gt;&lt;img src='media/title_status.png' alt='Status'/&gt;&lt;/td&gt; &lt;/tr&gt;"; echo "&lt;tr&gt; &lt;td&gt;&lt;div class='tpush'&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt;" while ($row = $result-&gt;fetch_object()) { echo "&lt;tr&gt;"; echo "&lt;td&gt;&lt;a href='records.php?id=" . $row-&gt;id . "'&gt;" . $row-&gt;item . "&lt;/a&gt;&lt;/td&gt;"; echo "&lt;td&gt;" . $row-&gt;priority . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli-&gt;error; } // close database connection $mysqli-&gt;close(); </code></pre>
 

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