...

View Full Version : could not print out value



kamkam
11-13-2011, 01:22 AM
Hi;

My problem is i could not print out value after i inserted echo "<div class=\"hints\">; and echo "</div>"; please see the highline .

I am implementing an auto suggestiion for search engin.

response.php


<?php
$q=$_GET["q"];
include("../condatabase.php");

$sql="SELECT content FROM articles WHERE content like '%".$q."%'";


$result = mysql_query($sql);

$a[]=""; $m[]="";



while($row = mysql_fetch_array($result)){
$m.= $row['content'];
}
//$final = preg_match_all("/talking a[a-zA-Z]*/", $string);
$term="/" . $q . "[a-zA-Z\s]*" . "/";

preg_match_all($term, $m,$f);



$count=count($f[0]);
$f[0]=array_unique($f[0]);


$i=0;
while($i<$count){
$a[$i]=($f[0][$i]);
echo "<div class=\"hints\">;
echo $a[$i]; // i could not print out this value, but it can do without two div
echo "</div>";
$i++;
}

?>

-------------------------------------------------------------------
index.php


<html>
<head>
<script type="text/javascript">
function showHint(str)
{

var xmlhttp;
if (str.length==0)
{
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","response.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<h3>Start typing a name in the input field below:</h3>
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>


</body>
</html>

mlseim
11-13-2011, 02:36 AM
Maybe the CSS style for your "hints" class is normally hidden or invisible?

Show us your style sheet.

kamkam
11-13-2011, 02:54 AM
it does not have any css for it yet

mlseim
11-13-2011, 03:14 AM
Why do you need a <div> with the class called "hints"?
Especially if you have no CSS stylesheet.

Inigoesdr
11-13-2011, 04:02 AM
You're missing the close quote on your first div line. You are getting an syntax error, and presumably display_errors is off so you get no output. Please remember to read the stickies for this forum. In particular the one about using
tags (http://www.codingforums.com/showthread.php?t=68462) when posting code.

mlseim
11-13-2011, 04:03 AM
doh! I didn't see that ... good catch!

kamkam
11-13-2011, 06:09 AM
Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum