I'm a newbie on php, javascript and ajax. I got this tutorial about How to Create a Search Feature with PHP and MySQL and it was a success after creating it. Link: http://www.webreference.com/programming/php/search/index.html
Now I'm changing the index.html file and linked only to search_display.php file for just a simple price checker program. I was confuse on how to link the "code" result under Javascript function doScan(code)
to search_display.php
.
<script>
function doScan(code) //displays the value target after scanning.
{
divStatus.innerHTML = 'Scanned Code:<br> ' + code;
setTimeout("startScanner()", 1250);
}
</script>
I wanted to link "code" to search_display.php
and this is the code:
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
//if(preg_match("/^[a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//connect to the database
$db=mysql_connect("localhost", "root", "bbp0m") or die ('I cannot connect to the database because: ' . mysql_error());
//var_dump($db);
//-select the database to use
$mydb=mysql_select_db("price_checker");
//var_dump($mydb);
//-query the database table
$sql="SELECT * FROM stock_master WHERE gtin LIKE '%" . @$name . "%'";
//var_dump($sql);
//-run the query against the mysql query function
$result=mysql_query($sql);
//var_dump($result);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$itemcode=$row['itemcode'];
$desc1=$row['desc1'];
$desc2=$row['desc2'];
$uom=$row['uom'];
$gtin=$row['gtin'];
$retailprice=$row['retailprice'];
//-display the result of the array
echo "<ul>
";
echo "<li>" . "<a href=\"index.html?id=$gtin\">" .$itemcode . " " . $desc1 . " " . $desc2 . " " . $uom . " " . $gtin . " " . $retailprice . "</a></li>
";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
//}
?>
Any ideas how to link it and if possible I would like to put everything into index.html
?
Bert