{"id":5902676,"date":"2015-03-16T04:02:18","date_gmt":"2015-03-16T04:02:18","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/sql-results-into-html-table\/"},"modified":"2016-08-22T18:04:58","modified_gmt":"2016-08-22T18:04:58","slug":"sql-results-into-html-table","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/sql-results-into-html-table\/","title":{"rendered":"SQL Results into HTML Table"},"content":{"rendered":"<p>Hi i am new to this, however, i feel i am learning and getting on with it. however i have ran into a problem.<\/p>\n<p>the insert php i have got working on this page but the results are not great in terms of they need formatting<br \/>\nhttp:\/\/luxor-lettings.com\/our-properties\/click-through\/<\/p>\n<p>but i want to get the results into a HTML table so i have attempted it on another page &#8211; i have attempted with the following code on this page:<br \/>\nhttp:\/\/luxor-lettings.com\/results-2\/<\/p>\n<p>&lt;html&gt;<br \/>\n    &lt;head&gt;<br \/>\n        &lt;title&gt;Available Properties&lt;\/title&gt;<br \/>\n    &lt;\/head&gt;<br \/>\n    &lt;body&gt;<br \/>\n        &lt;table&gt;<br \/>\n        &lt;thead&gt;<br \/>\n            &lt;tr&gt;<br \/>\n                &lt;td&gt;Property Image&lt;\/td&gt;<br \/>\n                &lt;td&gt;Property Description&lt;\/td&gt;<br \/>\n                &lt;td&gt;Property Availability&lt;\/td&gt;<br \/>\n            &lt;\/tr&gt;<br \/>\n        &lt;\/thead&gt;<br \/>\n        &lt;tbody&gt;<br \/>\n[insert_php]<br \/>\n$servername = &#8220;db567706584.db.1and1.com&#8221;;<br \/>\n$username = &#8220;username&#8221;;<br \/>\n$password = &#8220;password&#8221;;<br \/>\n$dbname = &#8220;db567706584&#8221;;<br \/>\n\/\/ Create connection<br \/>\n$conn = new mysqli($servername, $username, $password, $dbname);<br \/>\n\/\/ Check connection<br \/>\nif ($conn-&gt;connect_error) {<br \/>\n    die(&#8220;Connection failed: &#8221; . $conn-&gt;connect_error);<br \/>\n}<br \/>\n$sql = &#8220;SELECT <code>Property Thumbnail URL<\/code>,<code>Property Title4HTML<\/code>,<code>Image Tag<\/code> FROM <code>Properties<\/code>,<code>Available<\/code> WHERE <code>Property Available Flag<\/code> = <code>Flag<\/code> AND <code>Property Available Flag<\/code> = &#8216;2&#8217;&#8221;;<br \/>\n$result = $conn-&gt;query($sql);<br \/>\nif ($result-&gt;num_rows &gt; 0) {<br \/>\n    \/\/ output data of each row<br \/>\n    while($row = $result-&gt;fetch_assoc()) {<br \/>\n            [\/insert_php]<br \/>\n                &lt;tr&gt;<br \/>\n                    &lt;td&gt;[insert_php] echo $row[&#8216;Property Image&#8217;][\/insert_php]&lt;\/td&gt;<br \/>\n                    &lt;td&gt;[insert_php] echo $row[&#8216;Property Description&#8217;][\/insert_php]&lt;\/td&gt;<br \/>\n                    &lt;td&gt;[insert_php] echo $row[&#8216;Property Availability&#8217;][\/insert_php]&lt;\/td&gt;<br \/>\n                &lt;\/tr&gt;<br \/>\n            [insert_php]<br \/>\n    }<br \/>\n} else {<br \/>\n    echo &#8220;0 results&#8221;;<br \/>\n}<br \/>\n$conn-&gt;close();<br \/>\n[\/insert_php]<br \/>\n&lt;\/tbody&gt;<br \/>\n            &lt;\/table&gt;<br \/>\n    &lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>but i get get errors &#8211; any help appreciated<\/p>\n<p>what should i be changing to get the results into a table? thanks<\/p>\n<p>https:\/\/wordpress.org\/plugins\/insert-php\/<\/p>\n","protected":false},"template":"","class_list":["post-5902676","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5902676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5902676\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5902676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}