My code is functioning as intended, where a search is performed in the table based on user input, displaying the attributes within an HTML table. For a clearer picture, I will provide an image of the search output: Output of the Search
However, due to the presence of printf in the code, I am facing uncertainty regarding how to properly output the data into my table. There are 12 attributes selected and the implementation involves the use of AJAX and JavaScript.
Here is a snippet from the index.html:
<br><br>
<!-- Search box -->
<form method="post" action="index.php">
<input type="text" id="search" name="search" required placeholder="Search for an item" /><input type="submit" value="LOAD"/>
<br></form>
<b>Ex: </b><i>Bread, Milk, Egg, etc or SKU</i>
<br />
<!-- Suggestions displayed below -->
<div id="display"></div>
<table id="itemsTable">
// Table headers...
</tr><tr><td>
<?php
if (isset($_POST['search'])) {
// SEARCH FOR ITEM NAME
require "2-search.php";
// DISPLAY RESULTS
if (count($results) > 0) {
foreach ($results as $r) {
printf("<div>%s - %s - %s - %s - %s - %s - %s - %s - %s - %s - %s- %s</div>", $r['quantity'], $r['item'], $r['sku'], $r['item_name'], $r['item_price'], $r['subtotal'], $r['cartons_scanned'], $r['ind_scanned'], $r['cur_inventory'], $r['location_sel'], $r['image'], $r['edit']);
}
} else {
echo "No results found";
}
}
?>
</td></tr></table>
<br><br><br>
For the 2-search.php file:
<?php
// Database configuration...
// Connect to database...
// Search logic...
Lastly, the 3-ajax-search:
<!DOCTYPE html>
<html>
<head>
<title>
AJAX Search Example
</title>
<script>
// JavaScript function for fetching search results...
</script>
</head>
<body>
<!-- Search form -->
<form onsubmit="return fetch();">
<h1>SEARCH FOR USERS</h1>
<input type="text" id="search" required/>
<input type="submit" value="Search"/>
</form>
<!-- Search results div -->
<div id="results"></div>
</body>
</html>