Hi I'm a student working to finish my final year project. Got caught up with a problems where by my similar_text function is not working properly. It didn't return the percent value back. Only list zero number. Used it before and it was okay. Did some alterations for other parts and after that, it started to happen... Can anyone help me??
And one more thing, if u realise it below, the if part use no $ sign. When i put the $ sign, it just gives out weird results. Would anyone explain why???😕
For anyone who wants the database to test it out, you can e-mail me...
Here are the php codes :
<?php
include ("doumeta.php");
$studdb = mysql_pconnect("localhost","root","");
mysql_select_db("elearn_student_db",$studdb);
$studdb2 = mysql_pconnect("localhost","root","");
mysql_select_db("elearn_student_db",$studdb2);
?>
<h2 style="text-align:center">A DOUBLE METAPHONE SEARCH ENGINE</h2>
<p> </p>
<h4 style="text-align:center"> Give the best suggestion for your name search - TRY IT!! </h4>
<form id="form1" name="searchform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div align="center"><label for="textfield" class="alignTopLeft"><strong>Names</strong></label></div>
<div align="center"><input type="text" name="names" id="names" align="center" size="50" /></div>
<div align="center"><input type="submit" name="Submit" value="Submit" id="Submit" /></div>
</form>
<p> </p>
<hr />
<h2>Results</h2>
<p>
<?php
// Get the search variable from URL
if (isset($POST['names'])) {
$studName = $POST['names'];
} else {
die('');
}
$trimmed = trim($studName);
if ($studName == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
// check for a search parameter
if (!isset($studName))
{
echo "<p>No search parameter!</p>";
exit;
}
$stopper = false;
$query2 = "SELECT common_names FROM common_name";
$result2 = mysql_query ( $query2 , $studdb2);
while (($row2 = mysql_fetch_array($result2 , MYSQL_ASSOC)) && (!$stopper)){
echo "One";
$temp = $row2['common_names'];
echo $studName;
echo $temp;
$pos1 = stripos ( $studName , $temp . " " );
if ( pos1 == true ){
$pieces = explode($temp . " ", $studName);
if ( empty ($pieces[1])){
continue;}
echo "Side 1:" . $pieces[0] . " <br/> ";
echo "Side 2:" . $pieces[1] . " <br/> ";
$stopper = true;
}
}
$namesHash2 = double_metaphone($pieces[1]);
$primary = $namesHash2['primary'];
$query = "SELECT nama FROM student_jul09 WHERE hash_clean_name like " . "'$primary'" . "ORDER BY
nama";
echo $primary;
echo "<br/>";
$search=mysql_query($query , $studdb2);
echo mysql_error();
$numrows=mysql_num_rows($search);
if ($numrows < 1)
{
echo "<h4 >Results</h4>";
echo "<p>Sorry, your search: "" . $studName . "" returned zero results</p>";
}
// next determine if it has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// begin to show results set
echo "Results";
echo $studName;
$count = 1 + $s ;
// display the results returned
$counter = 0;
while ($row= mysql_fetch_array($search)) {
$title = $row["given_name"];
echo $title;
similar_text ( $row["given_name"] , $studName , &$percent );
$holdValue[$counter] = $percent;
$nameValue[$counter] = $row["nama"];
$counter = $counter + 1;}
?>
<table border = 1>
<tr>
<?php for ( $k = 0; $k <= sizeof ($nameValue) ; $k++)
{
?>
<td><?php echo "$count.)";?></td>
<td><?php echo " $nameValue[$k]"; ?> </td>
<td><?php echo " $holdValue[$k]"; ?> </td>
</tr>
<?php
$count++ ;
echo "<br/>";
}
?>
</table>