pjheliking Posted October 2, 2008 Share Posted October 2, 2008 Hi, I am doing a project for uni and need help as its the only thing i am stuck on. Im doing a little linking site which is not due for 3 weeks so started it a couple of hours ago and well needing help I have decided to do a linking site for tv movies but i have only put 2 examples on the server as im not wanting sued!! Anyways unless you do the exact search scrubs or lee evans you wont see results what I need to be able to do is query the mysql database and basicly the closest match gets displayed. I have done everything else to allow for this but i have been looking into the match sql query but i have a feeling im way off track. http://tvlinks.ctc-media.co.uk Can you give me any advice or point me in the redirection ... thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/ Share on other sites More sharing options...
dennismonsewicz Posted October 2, 2008 Share Posted October 2, 2008 use the LIKE command in SQL http://www.techonthenet.com/sql/like.php Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-655972 Share on other sites More sharing options...
pjheliking Posted October 2, 2008 Author Share Posted October 2, 2008 looks like its on the same track just trying to figure out how to use it lol Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-655975 Share on other sites More sharing options...
richiec Posted October 2, 2008 Share Posted October 2, 2008 $search= $_REQUEST["search"]; SELECT * FROM tablename WHERE moviefield LIKE '$search'; you mean something like that? Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-655982 Share on other sites More sharing options...
DeanWhitehouse Posted October 2, 2008 Share Posted October 2, 2008 I would say this one is better <?php $search= "%".$_REQUEST["search"]."%"; SELECT * FROM tablename WHERE moviefield LIKE '$search'; ?> But up to you, depends how you want the search. Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-655984 Share on other sites More sharing options...
richiec Posted October 2, 2008 Share Posted October 2, 2008 but hes using like so the before and after of $search wouldnt matter would it? it would still find the ones which match it best either way wouldnt it? not sure though.. Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-655986 Share on other sites More sharing options...
pjheliking Posted October 2, 2008 Author Share Posted October 2, 2008 thanks peeps.. not solved but great... the first bit of code didnt work the second shows everything from the database you have gave me something to work on thanks heres my code $tvlink = mysql_pconnect($hostname_tvlink, $username_tvlink, $password_tvlink) or trigger_error(mysql_error(),E_USER_ERROR); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_link = "-1"; if (isset($_POST['title'])) { $colname_link = $_POST['title']; } mysql_select_db($database_tvlink, $tvlink); $query_link = sprintf("SELECT * FROM linker WHERE tags LIKE '$disp'; ", GetSQLValueString($colname_link, "text"),GetSQLValueString("%" . $colname_link . "%", "text")); $link = mysql_query($query_link, $tvlink) or die(mysql_error()); $row_link = mysql_fetch_assoc($link); $totalRows_link = mysql_num_rows($link); Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-655987 Share on other sites More sharing options...
pjheliking Posted October 2, 2008 Author Share Posted October 2, 2008 mmmmmm im on the right track me thinks but it will have to wait...... http://tvlinks.ctc-media.co.uk/find.php thats where the search is i have implamented all that was said and wat i have picked up in tutorials online for example try lee evans it will give you the links. Try lee nope not working.. I was hoping to use a tagging system but i think it will be a drop down search array now Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-656005 Share on other sites More sharing options...
DeanWhitehouse Posted October 2, 2008 Share Posted October 2, 2008 You can also using the wildcard multiple times within the same string. For example, SELECT * FROM suppliers WHERE supplier_name like '%bob%'; In this example, we are looking for all suppliers whose name contains the characters 'bob'. Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-656006 Share on other sites More sharing options...
pjheliking Posted October 2, 2008 Author Share Posted October 2, 2008 i read that one lol. could i make a dynamic sql statement? mmmm try that the morra Quote Link to comment https://forums.phpfreaks.com/topic/126820-php-mysql-search/#findComment-656007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.