Example #1
0
function search_product()
{
    if (!isset($_REQUEST['st'])) {
        //return error
        echo '{"result":0,"message": "search did not work."}';
    }
    $search_text = $_REQUEST['st'];
    include "products.php";
    $obj = new products();
    if (!$obj->search_by_name($search_text)) {
        //return error
        echo '{"result":0,"message": "search did not work."}';
        return;
    }
    //at this point the search has been successful.
    //generate the JSON message to echo to the browser
    $row = $obj->fetch();
    echo '{"result":1,"products":[';
    //start of json object
    while ($row) {
        echo json_encode($row);
        //convert the result array to json object
        $row = $obj->fetch();
        if ($row) {
            echo ",";
            //if there are more rows, add comma
        }
    }
    echo "]}";
    //end of json array and object
}
Example #2
0
						 		
					</div>
					<div id="divStatus" class="status">
						status message
					</div>
					<div id="divContent">
						Content space
						<span class="clickspot">click here </span>
						<?php 
include_once "products.php";
$obj = new products();
$search_text = "";
if (isset($_REQUEST['txtSearch'])) {
    $search_text = $_REQUEST['txtSearch'];
}
$obj->search_by_name($search_text);
echo "<table border='1' id='prodTable'>";
echo "<tr style='background-color:olive; color:white; text-align:center'><td></td><td>Name</td><td>Price</td><td>manufacturers</td><td></td></tr>";
$row = $obj->fetch();
$style = "";
$i = 0;
while ($row) {
    if ($i % 2 == 0) {
        $style = "style='background-color:Khaki'";
    } else {
        $style = "";
    }
    echo "<tr {$style} >";
    echo "<td><input type='checkbox' id=''products[]' name='products[]' value='{$row['product_id']}'></td>";
    echo "<td><span class='clickspot' onclick='getDesc({$row['product_id']})'>{$row['product_name']}<span></td>";
    echo "<td>{$row['product_price']}</td> <td>{$row['manf_id']}</td>";