/ Published in: PHP
Im pretty new to oop php i have tried to create a php search function but im sure this needs alot of improvement. So add on :D
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public function search($string) { { return "Woow too many words, please shorten your search."; } { return "I'm a search, you type things in and I find. Please enter something and try again!"; } { return "Come on dude, you expect me to find summin with that? Type some more tags in!"; } $x=0; // Teh string could be multiple searches so explode:: foreach($string as $search) { $x++; if($x == 1) { @$sql .= "(blog_tags LIKE '%$search%')"; } else { @$sql .= " OR (blog_tags LIKE '%$search%')"; } } $sql = "SELECT blog_tags FROM subarc_blog WHERE $sql LIMIT 40"; // TODO:: Count how many search results found:: $stmt = $this->conn->prepare($sql); $stmt->execute(); $meta = $stmt->result_metadata(); while($field = $meta->fetch_field()) { $var = $field->name; $$var = null; $params[$var] = &$var; } while($stmt->fetch()) { return $params; } $stmt->close(); }