SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Help PHP + AJAX

  1. #1
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Help PHP + AJAX

    Hi i am alan
    I'm new using PHP + AJAX

    this is code
    [HIGHLIGHT=HTML4Strict]
    <html>
    <head><title>Master Desain</title>
    <script>
    function showHint(str)
    {
    if (str.length==0)
    {
    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 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","getbahan.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>

    <p><b><span class="style17">Ketikan Nama Bahan : </span></b>
    <input type="text" onKeyUp="showHint(this.value)" size="20" />
    </p>
    <p><span class="style17">Suggestions:
    Attached Images Attached Images
    Last edited by Dark Tranquility; Oct 12, 2012 at 02:49.

  2. #2
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,458
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Please repost your code and use code syntax highlight function of the editor.

  3. #3
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Syntax With Highlight

    this is index.php

    Code HTML4Strict:
    <html>
    <head><title>Master Desain</title>
    <style type="text/css">
    .style17 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; }
    .style18 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; font-style: italic; }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script>
    function showHint(str)
    {
    if (str.length==0)
      {
        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 && xmlhttp.status==200)
          {
          document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
          }
        }
      xmlhttp.open("GET","getbahan.php?q="+str,true);
      xmlhttp.send();
      }
    </script>
    </head>
    <body>
     
    <p><b><span class="style17">Ketikan Nama Bahan : </span></b>
      <input name="bahan" type="text" class="style17" id="bahan" onKeyUp="showHint(this.value)" size="20" maxlength="15" />
    </p>
    <p><span class="style17">Suggestions:</span> <span id="txtHint"> </span></p>
     
    </body>
    </html>

    this is getbahan.php
    Code PHP:
    <html>
    <head><title>Master Desain</title>
    <style type="text/css">
    .style17 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; }
    .style18 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; font-style: italic; }
    </style>
     
    <?php
     
    // session_start();
    require_once("./Connections/condesain.php");
    mysql_select_db("$dbName") or die("Could find table ".mysql_error());
     
    $bhn=$_GET["q"];
     
    $sql = mysql_query("SELECT * FROM desain-a WHERE bahan = '$bhn'");
     
        $numrows = mysql_num_rows($sql);
     
        echo "<table border='1'>
        <tr>
        <th>ID</th>
        <th>Kode</th>
        <th>Bahan</th>
        <th>Sub</th>
        <th>Lebar</th>
        <th>Pcs</th>
        <th>Stock</th>
        <th>Gambar</th>
        </tr>";
          if ($numrows !=0)
            {
              while($row = mysql_fetch_array($sql))
                {
                  echo "<tr>";
                  echo "<td>" . $row['id'] . "</td>";
                  echo "<td>" . $row['kode'] . "</td>";
                  echo "<td>" . $row['bahan'] . "</td>";
                  echo "<td>" . $row['sgrp1'] . "</td>";
                  echo "<td>" . $row['grp1'] . "</td>";
                  echo "<td>" . $row['pcs'] . "</td>";
                  echo "<td>" . $row['stock'] . "</td>";
                  echo "<td>" .$row[$image['gambar']]. "</td>";
                  echo "</tr>";
                }
              echo "</table>";
            }
          else
            echo " Data Tidak ditemukan.";
    ?>
    </head>
    </html>

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums.

    I think you forgot to post your question?

  5. #5
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    question is i want to show data from table when typing a letter into text box


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •