have a Class more exactly a HashClass() and a public method in that class is searchHash()
Heres the code:
[code=php]
public function searchHash()
{
$keyword=$_POST['hash'];
$array=explode(' ', $keyword);
//The users text is parsed and exploded into an array
foreach($array as &$value)
$value=$this->hash($value);
//Here each word corresponding to each array position is transformed into integer values based on the hash function
shuffle($array); //shuffle the array
//I tried to use shuffle to obtain better performance when traversing the array, Im open for suggestions here, Im not really into sequential comparison so I would like something random
reset($array); //reset the cursor in the array
mysqli_autocommit($this->dbconnect->lincs, FALSE);
foreach($array as $val)
{
$var=$val; //here I wanted to pass to a variable each value in the array
$result=$this->dbconnect->query("select tag,describ from taguri,categorii where id_tag=$var and taguri.id_cat=categorii.id_cat"); //then try to see which fits
if($result){//if the query dosen`t return 0, it means it fited -> $var == id_tag
$row=$this->dbconnect->fetchArray($result,MYSQL_ASSOC); //assign to $row the result
mysqli_commit($this->dbconnect->lincs);
break; //if id_tag and $row == then exit the for loop
}else if(mysqli_errno($this->dbconnect->lincs))
mysqli_rollback($this->dbconnect->lincs);
}
$result="<tr><td>$row[tag]</td><td>$row[describ]</td></tr>"; //print the results under an html table
return $result;
}
[/code]
I have a Class_ctrl file
$hash = new HashClass();
$actType = "";
if(isset($_GET['actType'])){
$actType=$_GET['actType'];
}
if($actType=="Insert")
header("Location:". $hash->insertHash()); //if the argument "insert" is passed through form submit then load this
if($actType=="Search")
header("Location:".$hash->searchHash());//if the argument "Search" is passed through form submit then load this
f($actType=="Delete")
header("Location:".$hash->deleteHash());//if the argument "Delete" is passed through form submit then load this
So heres what Its really happening:
1. User enters some text in the form say: "I want to buy a BMW "
2. User selects the "search" radio button then "Submits"
3. The forms action is "Class_ctrl?actType=search", the action is changed dynamicaly by javascript
4. Method searchHash() should return the tag correspondig to the hash value and it`s description.
BUT
Method searchHash() dosent return my results and what Im afraid what happens is that once mysql sends an error it closes the connection and dosen`t try again( as it should do by reentering the foreach loop )
Can somebody please suggest me a solution?