mysql - select name from php query and refresh seprate query on same page. -
i have used first bit of ajax search mysql database. persons name add href result (which have) , post seprate page show the relevant details, eg address, grade , location. wondering if possible staying on same page. have far. ( , yes css moving seprate page)
<?php if(!strlen(trim($_session['unique_id']))) { header("location:roster.php"); exit(); } ?> <title>search roster</title> <style> body { font-family: "lucida grande", verdana, arial, sans-serif; font-size: 12px; } #results { color: #fff; background: #414141; width: 180px; max-height: 200px; padding-left: 4px; border: 1px solid #000; overflow-y: scroll; overflow-x: hidden; } { color: #fff; display: block; } a:hover { background: #666666; } </style> keyword search: <form id="searchform" method="post" onsubmit="return false;"><input autocomplete="off" id="searchbox" name="searchq" onkeyup="sendrequest()" type="textbox"> </form><div id="show_results"></div><script src="config/prototype.js" type="text/javascript"> </script> <script> function sendrequest() {new ajax.updater('show_results', 'pages/login/search.php', { method: 'post', parameters: $('searchform').serialize() }); } </script> <?php include("pages/include/footer.php"); ?> and search.php page
<?php $host="****"; // host name $sqlusername="****"; // mysql username $sqlpassword="****"; // mysql password $db_name="****"; // database name $tbl_name="****"; // table name mysql_connect("$host", "$sqlusername", "$sqlpassword")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $searchq = $_post['searchq']; if(empty($searchq)) { echo ""; } else { echo "<div id='results'-->"; //this query searches name field whatever input is. $sql = "select * user employee '%$searchq%' or staff '%$searchq%'"; echo "<table border='3'> <tr> </tr>"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $name = $row['employeename']; $id=$row['unique_id']; echo "<a href=anotherpage.php?item=".$id."</a>"; echo "$name"; echo "</br>"; } echo "</div>"; } ?>
you have did mistake in following line of code in "search.php". verify other line of code.
echo "<a href=anotherpage.php?item=".$id."</a>"; echo "$name"; above code should follows :
echo "<a href=anotherpage.php?item=".$id.">".$name."</a>";
Comments
Post a Comment