masterjiraya -3 Junior Poster

the code in php:
name it as postback.php

<?php
$q=$_GET['q'];
$query_type=$_GET['query_type'];
$words=explode(' ',$q);
$con = mysql_connect('localhost', 'root', '')or  die('Could not connect: ' . mysql_error());
mysql_select_db("clc_books", $con)or die('cannot connect');
$q = preg_replace('/\s\s+/', ' ', $q); // remove extra space
echo "<table border='1'>";
echo"
<tr>
<th>book id</th>
<th>book number</th>
<th>book name</th>
<th>Author</th>
<th>SRP</th>
</tr>";
$operator="";
$condition="";
for( $i = 0; $i < count($words); ++$i ){
	$condition.=$operator." CONCAT(".$query_type.") LIKE  CONVERT(_utf8 '%".$words[$i]."%' USING latin1) COLLATE latin1_swedish_ci";
	$operator=" OR ";
}
$sql = "SELECT *,CONCAT(".$query_type.") as fullname FROM `clc_books_list`   ";
if ($condition!="")
$sql .= " where ($condition) ";
$result = mysql_query($sql) or die('cannot query '.mysql_error($result));
$found=false;
while($row = mysql_fetch_array($result))
  {
 $found=true;
  echo "<tr>";
  echo "<td bgcolor='#ffff80'>" . $row['book_id'] . "</td>";
  echo "<td bgcolor='#80ffff'>" . $row['book_number'] . "</td>";
  echo "<td bgcolor='#ff8c8c'>" . $row['bookname'] . "</td>";
  echo "<td  bgcolor='#ff8040'>" . $row['Author'] . "</td>";
  echo "<td  bgcolor='#ff7000'>" . $row['SRP'] . "</td>";
  echo "</tr>";
  }
if(!$found){
echo "<tr align='center'><td colspan=5 bgcolor='yellow'><b>NO<b> similar names with <font color=red><b>"./*$words[$wordCount2]*/$q.'</b></font></td></tr>';
  }
echo "</table>";
mysql_close($con);
?>

code in html where the problem is:
index.html

<html>
<head>
<script type="text/javascript">
function showUser(str, query)
{
if(document.getElementById("Author").checked=true)
{
    query="author"
}
if (str=="")
  {
  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","postback.php?q="+str+"?query_type="+query,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<input type="text" name="users" onkeyup="showUser(this.value)">
    </input></br>Search By</br>Author
<input type="radio" name="query_type" id="Author" onclick="showUser()"/>or by<input type="radio" name="query_type" id="bookname" onclick="showUser()"/>book name
    </form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

Here's my problem. I'm kinda sort of "Memory Drained" because of thinking and thinking to this problem.... in the textbox field without radio button... I can get the values by default... replacing the $query_type in the mysql_db_query in to a certain default name in the database table... but what I want is to let the user select between book name or author. For instance a customer doesn't remember the title of the book but it remembers the Author of the book, or even the other way around, there he may be able to search the book he want that fast...

I feel that something is lacking around

xmlhttp.open("GET","postback.php?q="+str+"?query_type="+query,true);

can you please revise the code to my problem...?

thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.