[PHP-DB] Re: Help needed in searching a sentence in the code
nagendra prasad nagendra802...@gmail.com wrote in message news:aanlktinesp1vyn3do_ubcax9ltlhf5yqduwe24iam...@mail.gmail.com... Hi All, I have this code where user can search a song or the entire song title. It looks like when a user search a single word its searching and giving the proper results. However if the user wants to search the entire sentence its not giving the proper results. For example let say I have searched for the MJ's song Earth Song, its giving me the proper results. However if I am searching for the MJ's Why You Wanna Trip On Me, its not giving me the proper results. Below is the code: ?php //get data $button = $_GET['submit']; $search = $_GET['search']; $s = 0; $s = $_GET['s']; if (!$s) $s = 0; $i = 0; $e = 30; // Just change to how many results you want per page $next = $s + $e; $prev = $s - $e; if (strlen($search)=2) echo brtable align='center'trtdsupdagger;/supfont face='sana-serif' size='6'font color='blue'bsupa href=' http://localhost/searchengine/' style='text-decoration: none'MP3dom/a/sup/b/b/fontfont face='sana-serif' size='3'suptrade;/sup/tdtdsupform action='search.php' method='GET'input type='text' onclick=value='' size='50' name='search' value='$search' input type='submit' name='submit' value='Search'/form/td/tr/table table bgcolor='#FF' width='100%' height='1px'br //tabletable bgcolor='#f0f7f9' width='100%' height='10px'trtddiv align='right'bMust be greater then 3 chars/b/div/td/tr/tablep/sup; else { echo brtable align='center'trtddagger;font face='sana-serif' size='6'font color='blue'ba href='http://localhost/searchengine/' style='text-decoration: none'MP3dom/a/b/b/fontfont face='sana-serif' size='3'suptrade;/sup/tdtdsubform action='search.php' method='GET'input type='text' onclick=value='' size='50' name='search' value='$search'input type='submit' name='submit' value='Search'/form/td/tr/table/sub; //connect to database mysql_connect(localhost,root,); mysql_select_db(mp3); //explode out search term $search_exploded = explode( ,$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= name LIKE '%$search_each%'; else $construct .= OR name LIKE '%$search_each%'; } //echo outconstruct $constructx = SELECT * FROM data WHERE $construct; $construct = SELECT * FROM data WHERE $construct LIMIT $s,$e ; $run = mysql_query($constructx); $foundnum = mysql_num_rows($run); $run_two = mysql_query($construct); if ($foundnum==0) echo table bgcolor='#F1EDC2' width='100%' height='1px'br //tabletable bgcolor='#f0f7f9' width='100%' height='10px'trtddiv align='right'No results found for b$search/b/div/td/tr/tablep; else { echo table bgcolor='#F1EDC2' width='100%' height='1px'br //tabletable bgcolor='#f0f7f9' width='100%' height='10px'trtddiv align='right'Showing 1-30 of b$foundnum/b results found for b$search./b/div/td/tr/tablep; print 'table bgcolor=#F1EDC2 width=700 height=30 border=0 align=center '; print 'tr'; print 'td width=100 nowrap=nowrapstrongArtist/strong/td'; print 'td width=250 nowrap=nowrapstrongSong Name/strong/td'; print 'td width=50 nowrap=nowrapstrongMovie Date/strong/td'; print 'td width=50 nowrap=nowrapstrongSize/strong/td'; print '/tr'; while ($runrows = mysql_fetch_assoc($run_two)) { //get data $type = $runrows['artist']; $date = $runrows['date']; $name = $runrows['name']; $size = $runrows['size']; foreach ($runrows as $row) { if ($i % 2 != 0) # An odd row $rowColor = #EBECE4; else # An even row $rowColor = #FEF1E9; print 'table width=700 height=30 border=0 align=center'; } print '?php do { ?'; print 'tr bgcolor=' . $rowColor . ''; print 'td nowrap=nowrap width=100'.'font color=:blue size=2'.$type.'/td'; //print 'td nowrap=nowrap width=250'.'font size=2'.a herf='$url'$name.'/td'; print 'td nowrap=nowrap width=250'.'font color=blue size=2'.a href='download.php?url=$url'$name.'/font/td'; print 'td nowrap=nowrap width=100 align=center'.'font size=2'.$date .'/td'; print 'td nowrap=nowrap width=50'.'font size=2'.$size .'/td'; print 'td nowrap=nowrap width=25'.'font size=2'.$se .'/td'; print 'td nowrap=nowrap width=25'.'font size=2'.$le .'/td'; print '/tr'; print '/table'; print '/body'; print '/html'; } ? table width='100%' tr td div align=center brbr ?php if (!$s=0) echo a href='search.php?search=$searchs=$prev'Prev/a; $i =1; for ($x=0;$x$foundnum;$x=$x+$e) { echo a href='search.php?search=$searchs=$x'$i/a ; $i++; } if ($s$foundnum-$e) echo a href='search.php?search=$searchs=$next'Next/a; } } ? /div /td /tr /table *** Also, the above code is giving me the below
[PHP-DB] Re: Call two class object failed
win.a win@gmail.com wrote in message news:aanlktinhmyybnamty5sx5m-fyoztsywp1kxfnsexv...@mail.gmail.com... Hi my friend,i wrote two classed on is user,the other is db .The user have a property which from the db class object . When i writing my application have both class object invoked at the same time ,just like $user_a = new user($para); $db_a = new db() Then the problem occurs only one of the class object could work, or $user_a or $db_a not both,What 's problem of my code The following is my source code: class db{ /** * Constructor */ var $result; var $conn; function db(){ require_once BOC_BASE_DIR.'/config/db.config.inc'; $this-conn = mysql_connect($db_host,$db_user,$db_pass); //$this-conn = @mysql_connect($db_host,$db_user,$db_pass); if (!$this-conn) { $this-db_print_error(DB connect failed); } if (!mysql_select_db($db_name,$this-conn)) { $this-db_print_error(DB select failed); } } class user{ private $u_sn; private $u_id; private $u_name; private $u_sex; private $u_image; //more property private $u_info; /** * Constructor */ function __construct($name){ $sql = select * from boc_user where u_name = '$name'; $u_query = new db(); $this-u_info = array(); $u_query-db_query($sql); $this-u_info =$u_query-db_fetch_row(); $this-u_sn = $this-u_info['u_sn']; $this-u_id = $this-u_info['u_id']; $this-u_name = $this-u_info['u_name']; $this-u_sex = $this-u_info['u_sex']; //more are give the property value } The two class works well in the single application when only of them are invoked ,i cost me much time to deal it Any advice and suggestions are thankful ! All you best What we are struggling for ? The life or the life ? Hi, one way to do that: ?php class Database { private $link; function __construct() { $this-conn(); } function conn() { $this-link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME, $this-link); } function query($query) { return mysql_query($query, $this-link); } function fetch_assoc($result) { return mysql_fetch_assoc($result); } } class User { private $db; function __construct($db) { $this-db = $db; } function find_by_username($username) { $result = $this-db-query(select * from boc_user where username='$username'); return $this-db-fetch_assoc($result); } } $db = new Database; $user = new User($db); $userdata = $user-find_by_username('username'); ? I did not check the code, so there might be some typos. Anyway it should help you! Br Tanel -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Call two class object failed
win.a win@gmail.com wrote in message news:aanlktinhmyybnamty5sx5m-fyoztsywp1kxfnsexv...@mail.gmail.com... Hi my friend,i wrote two classed on is user,the other is db .The user have a property which from the db class object . When i writing my application have both class object invoked at the same time ,just like $user_a = new user($para); $db_a = new db() Then the problem occurs only one of the class object could work, or $user_a or $db_a not both,What 's problem of my code The following is my source code: class db{ /** * Constructor */ var $result; var $conn; function db(){ require_once BOC_BASE_DIR.'/config/db.config.inc'; $this-conn = mysql_connect($db_host,$db_user,$db_pass); //$this-conn = @mysql_connect($db_host,$db_user,$db_pass); if (!$this-conn) { $this-db_print_error(DB connect failed); } if (!mysql_select_db($db_name,$this-conn)) { $this-db_print_error(DB select failed); } } class user{ private $u_sn; private $u_id; private $u_name; private $u_sex; private $u_image; //more property private $u_info; /** * Constructor */ function __construct($name){ $sql = select * from boc_user where u_name = '$name'; $u_query = new db(); $this-u_info = array(); $u_query-db_query($sql); $this-u_info =$u_query-db_fetch_row(); $this-u_sn = $this-u_info['u_sn']; $this-u_id = $this-u_info['u_id']; $this-u_name = $this-u_info['u_name']; $this-u_sex = $this-u_info['u_sex']; //more are give the property value } The two class works well in the single application when only of them are invoked ,i cost me much time to deal it Any advice and suggestions are thankful ! All you best What we are struggling for ? The life or the life ? Hi, one way to do that: ?php class Database { private $link; function __construct() { $this-conn(); } function conn() { $this-link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME, $this-link); } function query($query) { return mysql_query($query, $this-link); } function fetch_assoc($result) { return mysql_fetch_assoc($result); } } class User { private $db; function __construct($db) { $this-db = $db; } function find_by_username($username) { $result = $this-db-query(select * from boc_user where username='$username'); return $this-db-fetch_assoc($result); } } $db = new Database; $user = new User($db); $userdata = $user-find_by_username('username'); ? I did not check the code, so there might be some typos. Anyway it should help you! Br Tanel -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php