PHP Classes

File: class.search.php

Recommend this page to a friend!
  Classes of sujith nair   search_fields   class.search.php   Download  
File: class.search.php
Role: ???
Content type: text/plain
Description: class file
Class: search_fields
Author: By
Last change:
Date: 23 years ago
Size: 1,575 bytes
 

Contents

Class file image Download
<?php // Class to search a keyword in mysql database // Made By Sujith Nair [[email protected]] // On September 12, 2001 class search_fields { var $hname; var $uname; var $pname; var $dbname; // Constructor if u have username and password function search_fields($h_name,$u_name=" ",$p_name= " ",$db_name) { $this->hname=$h_name; $this->uname=$u_name; $this->pname=$p_name; $this->dbname=$db_name; } function connect() { $db=mysql_connect($this->hname); mysql_select_db($this->dbname,$db); } function make_str($t_name,$keywords) { $sql="select * from $t_name"; $res=mysql_query($sql); // Count the number of fields in the table $cnt_fields=mysql_num_fields($res); $myrow=mysql_fetch_array($res); $str=""; for($i=0;$i<$cnt_fields;$i++) { $str.=mysql_field_name($res, $i)." like '%$keywords%' or "; } $str=substr($str,0,strlen($str)-3); $key="select * from $t_name where ".$str; $this->t_name=$t_name; $this->str=$str; } function showresult() { $key="select * from ".$this->t_name." where ".$this->str; //echo $key; $reskey=mysql_query($key); $cnt=mysql_num_rows($reskey); if($cnt == 0) { return 1; } else { echo "<u>"."Total $cnt results found"."</u><br><br>"; while($myrow=mysql_fetch_array($reskey)) { display($myrow); } } } // End of class } function display($rest) { // Display any field as you want // Replace <field index> with any of your field name. echo "$rest[<field index>]"; echo "<br>"; } ?>