Using php to populate html table -


i need populate table data regarding 10 countries using .php , .html file. have downloaded xampp (7.1.8) working on macbook pro 2012 running sierra (can not xampp-vm run - signal killed error message on start up).

i have created database testdb in mysql , coded database.html file , getuser.php file below , saved them htdocs folder on server - when renders, isn't picking xml file or data within.

i believe problem either on line 46 in php or line 36 in html, don't know enough php to know how change make work. appreciated,

thanks

suze

database.html

<head>      <script>          function showuser (str) {             if (str=="") {                 document.getelementbyid("txthint").innerhtml="";                  return;             }              if (window.xmlhttprequest)  {                  // code ie7+, firefox, chrome, opera, safari                  xmlhttp=new xmlhttprequest ();              } else { // code ie6, ie5                  xmlhttp=new activexobject ("microsoft.xmlhttp");              }              xmlhttp.onreadystatechange=function () {                  if (this.readystate==4 && this.status==200) {                      document.getelementbyid("hint").innerhtml=this.responsetext;                 }             }              xmlhttp.open("get","getuser.php?q="+str,true);             xmlhttp.send();         }      </script>  </head>  <body>      <form>      <select name="users" onchange="showuser(this.value)">          <option value ="">select country:</option>          <option value ="1">united kingdom</option>          <option value="2">france</option>          <option value="3">germany</option>          <option value="4">india</option>          <option value="5">hungary</option>          <option value="6">ireland</option>          <option value="7">greece</option>          <option value="8">usa</option>          <option value="9">japan</option>          <option value="10">spain</option>          </select>      </form>  <br>      <div id="hint"><b>country info highlighted below</b></div>  </body> 

getuser.php

<style>      table {          width: 100%;          border-collapse: collapse;     }      table, td, th {          border: 1px solid black;          padding 5px;      }      th {text-align: left;}  </style>  </head> 

<?php  $q = intval ($_get['q']);   $con = mysqli_connect('localhost', 'root', '');  if (!$con) {      die('could not connect: ' . mysqli_error($con)); }  mysqli_select_db($con,"testdb");  $sql = "select * records id = '".$q."'";  $result = mysqli_query($con,$sql);   echo "<table  <tr>  <th>country</th>  <th>capital city</th>  <th>currency</th>  </tr>";  error_reporting(e_error | e_parse);  while ($row = mysqli_fetch_array($result)) {      echo "<tr>";      echo "<td>" . $row['country'] . "</td>";      echo "<td>" . $row['capital city'] . "</td>";      echo "<td>" . $row['currency'] . "</td>";      echo "</tr>"; }  echo "</table>";  mysqli_close($con);  ?>  </body> 

the problem fetch array instead of assoziation. use mysqli_fetch_assoc(). can access array do.

while ($row = mysqli_fetch_assoc($result))

and close first table tag.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -