title: creating dynamic Div Tags for AJAX-PHP-MySQL generated table
body: <pre><code>&lt;?php
    $q=$_GET["q"];
  
    $con = mysql_connect('localhost', 'root', '');
    if (!$con)
        {
          die('Could not connect: ' . mysql_error());
         }
  
  mysql_select_db("world", $con);
  
  $sql="SELECT * FROM country WHERE Code = '".$q."'";
  
  $result = mysql_query($sql);
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  
  &lt;th&gt;Code&lt;/th&gt;
  &lt;th&gt;Name&lt;/th&gt;
  &lt;th&gt;Continent&lt;/th&gt;
  &lt;th&gt;GNP&lt;/th&gt;
  &lt;th&gt;GNPOld&lt;/th&gt;
  &lt;/tr&gt;";
  
  
  
  
  while($row = mysql_fetch_array($result))
     {
  
       echo "&lt;tr&gt;";  
       echo "&lt;td&gt;" . $row['Code'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['Name'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['Continent'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['GNP'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['GNPOld'] . "&lt;/td&gt;";
       echo "&lt;/tr&gt;";
        }
      echo "&lt;/table&gt;";
  
      mysql_close($con);
      ?&gt;
  </code></pre>
  
  <p>Above is PHP and below is HTML for same and I am working on sample world database of mysql now.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  function showUser(str)
  {
  if (str=="")
    {
    document.getElementById("txtHint").innerHTML="";
    return;
    } 
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
      }
    }
  xmlhttp.open("GET","moviedetail.php?q="+str,true);
  xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;table width="100%" border="0"&gt;
    &lt;tr&gt;
      &lt;td&gt;
  
  &lt;select name="Country" onChange="showUser(this.value)"&gt;
      &lt;option&gt;Select Name&lt;/option&gt;
      &lt;?php
      mysql_connect('localhost','root','')
      or die ("could not connect DB");
      mysql_select_db('world')
       or die ("could not connect database");
      $query="select code, name from country order by name asc"
       or die ("query failed");
      $result=mysql_query($query);
      while(list($code, $name)=mysql_fetch_row($result)) {
          echo "&lt;option value=\"".$code."\"&gt;".$name."&lt;/option&gt;";
      echo "&lt;div id=\"".$code."\"&gt;".$name."&lt;/div&gt;";
      }
      ?&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  
      &lt;td&gt;
      &lt;div id="txtHint"&gt;&lt;b&gt;Country info will be listed here.&lt;/b&gt;&lt;/div&gt;
  
      &lt;/td&gt; 
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This takes takes name from form and display table for same.
  My other set of codes are:-</p>
  
  <pre><code>&lt;?php
   for (;$i&lt;$nrows;)
  {   
  
       #add 1 so that numbers don't start with 0
  
        echo"&lt;tr&gt;\n";
      for ($j=0;$j&lt;10&amp;&amp;$i&lt;=$nrows;$j++)
      {
              $n = $i;
          $i=$i + 1;
          $k=$n%30;
  
          $row = mysqli_fetch_assoc($result);
          extract($row);
          echo "&lt;td&gt;
          &lt;table&gt;
          &lt;tr&gt;
                  &lt;td&gt;$n&lt;/td&gt;\n
          &lt;/tr&gt;\n
          &lt;tr&gt;
              &lt;td&gt;$Name&lt;/td&gt;\n
          &lt;/tr&gt;\n
          &lt;tr&gt;\n
              &lt;td&gt;$Continent&lt;/td&gt;\n
          &lt;/tr&gt;\n
          &lt;tr&gt;\n
              &lt;td&gt;$Region&lt;/td&gt;\n
          &lt;/tr&gt;\n
          &lt;tr&gt;\n
                  &lt;td&gt;$SurfaceArea&lt;/td&gt;\n
          &lt;/tr&gt;\n
          &lt;tr&gt;\n
              &lt;td&gt;$IndepYear&lt;/td&gt;\n
          &lt;/tr&gt;\n
              &lt;tr&gt;\n
              &lt;td&gt;$GNP&lt;/td&gt;\n
          &lt;/tr&gt;\n
          &lt;tr&gt;\n
              &lt;td&gt;$k&lt;/td&gt;\n
          &lt;/tr&gt;\n
      &lt;/table&gt;\n
  
  
          &lt;/td&gt;"; 
  
          if ($k==0)break 2;
  
      }
      echo"&lt;/tr&gt;\n";
  
  
  
  
  }
  ?&gt;          
  </code></pre>
  
  <p>and relevant sections of html is</p>
  
  <pre><code>  &lt;td&gt;&lt;table border="1"&gt;
    &lt;tr&gt;
      &lt;td&gt;
  
  
          &lt;?php
  include ("/connections/query.php");
  
  $nrows = mysqli_num_rows($result);
  /* Display results in a table */
      echo "&lt;table&gt;\n
      &lt;tr&gt;\n";
              $i=1;
  include ("/function/movietable.php");
  
  
      echo "&lt;/tr&gt;\n
      &lt;/table&gt;\n";
  
  
  ?&gt;  
  
  
      &lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;&lt;/td&gt;
  </code></pre>
  
  <p>I have few trouble with designing it. I want a mouseover effect(like in first two set of codes) showing more details about each country table(entire) generated by last two set of codes in column which is blank in code right above. I want it to remain displayed always at same position despite the page movement.</p>
  
  <p>And I have one more simple problem. As you can see above I have stopped query at 30 results. I want to add a show-more button at bottom to show more results on same page.</p>
  
  <p>I am a newbie, so it would be pretty much helpful if u point out mistakes in the codes. Till now it is working perfectly on localhost.</p>