Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:31:59+00:00 2026-06-11T15:31:59+00:00

I’m not really familiar with Ajax Response – I have edited the PHP Ajax

  • 0

I’m not really familiar with Ajax Response – I have edited the PHP Ajax Search code from W3schools.com as follows :

<?php
require_once('connect_db.php');

$query = "select item_no from items";
$result = mysql_query($query);
$a = array();

while ($row = mysql_fetch_assoc($result)){
    $a[] = $row['item_no'];
}

//get the q parameter from URL
$q=$_GET["q"];

//lookup all hints from array if length of q>0
if (strlen($q) > 0)
  {
  $hint="";
  for($i=0; $i<count($a); $i++)
    {
    if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
      {
      if ($hint=="")
        {
        $hint=$a[$i];
        }
      else
        {
        $hint=$hint." , ".$a[$i];
        }
      }
    }
  }

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
  {
  $response="No Suggestion";
  }
else
  {
  $response=$hint;
  }

//output the response
echo "<table border=1><tr><td>".$response."</td></tr></table>";

?>

The output of the above code works perfectly, but they are all listed like this (2L500BU , 2L500GO , 2L500NA , 2L500RD , 2L802CA , 2L802WH , 2L803GR , 2L804BE , 2L804BK , 2L804CO , 2L805BU , 2L806BE , 2L806GR ) – Those numbers are Item No in mysql table called items.

Now :

1) I want to output the response into table with <tr> for each like this

2l500BU

2L500GO

.

.

.

.
etc.

2) Do you think its possible to output all table records from Mysql based on the hint entered as follows :

$sql="SELECT * FROM items WHERE item_no = '".**$hint**."'";

$result = mysql_query($sql);

echo "<table align='center' cellpadding='3' cellspacing='3' width='800px' border='1' font style='font-family:arial;'>";
echo "
<tr align=center>
<th style=font-size:18px; bgcolor=#20c500>Item Number</th>
<th style=font-size:18px; bgcolor=#20c500>QTY</th>
<th style=font-size:18px; bgcolor=#20c500>Actual Price</th>
<th style=font-size:18px; bgcolor=#20c500>Selling Price</th>
<th style=font-size:18px; bgcolor=#20c500>Difference</th>
<th style=font-size:18px; bgcolor=#20c500>Date</th>
</tr>";


while($row = mysql_fetch_assoc($result)){

echo "<tr align=center bgcolor=#e3e3e3>";
  echo "<td style='font-size:18px; font-weight:bold;'>" . strtoupper($row['item_no']) . "</td>";
  echo "<td style='font-size:18px; font-weight:bold;'>" . $row['qty'] . "</td>";
  echo "<td style='font-size:18px; font-weight:bold;'>" . $row['actual_price'] . "&nbsp;<font style=font-size:12px;>JD</font></td>";
  echo "<td style='font-size:18px; font-weight:bold;'>" . $row['discount_price'] . "&nbsp;<font style=font-size:12px;>JD</font></td>";
  echo "<td style='font-size:18px; font-weight:bold;'>" . $row['difference_price'] . "&nbsp;<font style=font-size:12px;>JD</font></td>";
  echo "<td style='font-size:18px; font-weight:bold;'>" . date("d-m-Y",strtotime($row['date'])) . "</td>";
  echo "</tr>";

}
echo "<table>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:32:00+00:00Added an answer on June 11, 2026 at 3:32 pm

    If you’re wanting to fetch items from a database and display a row for each of them, this is how you’d do it with jQuery.

    Your PHP script:

    <?php
        $mysqli = new mysqli('localhost', 'user', 'password', 'database');
        $sql = "SELECT item_no FROM items";
        $res = $mysqli->query($sql);
        while ($row = $res->fetch_assoc()) {
            $rows[] = $row['item_no'];
        }
        header('Content-Type: application/json');
        echo json_encode($rows);
    ?>
    

    And your HTML with the table:

    <!DOCTYPE html>
    <html>
      <head>
      </head>
      <body>
        <table>
          <thead>
            <tr>
              <th scope="col">Item No.</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
      </body>
    </html>
    <script src="js/lib/jquery.js"></script>
    <script>
        $(document).ready(function() {
            $.getJSON('yourscript.php', function(items) {
                $.each(items, function(i, item) {
                    $('tbody').append('<tr><td>' + item + '</td></tr>);
                });
            });
        });
    </script>
    

    I’ve also used MySQLi (MySQL improved) rather than the standard mysql_ functions, as the mysql_ library is deprecated and you should be using either MySQLi or PDO now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.