aeafisme23 Posted February 19, 2008 Share Posted February 19, 2008 This is a snippet of code from the search page (http://www.thegreatestsave.org/sms/view_records_contact_log.php) i created. In the search box you can enter any value you wish because it pulls all the results regardless just put in A if you want and it will say it's looking for 0 since the code is looking for an integer, if you put in an integer such as 3 it will say it's looking for 3 so i know the mechanics are working but not to the specifics i need. Please do not delete the records as it is working I have rigged it to pull results by erasing part of this: $searchcode_query = "SELECT * FROM contact_log WHERE station_id = '".$codes."'"; to $searchcode_query = "SELECT * FROM contact_log "; I understand my problem lies within the station_id = '".$codes . This script is being modified from another project i did using AREACODES such as 220 , 574 , etc. So the next line of code that i believe is the problem is the defining of $codes as it is converting or looking for an integer value (a number like 220), so when i put in text like (WUSA) it will say it searched for 0 'zero' because it's looking for an integer. foreach($keywords as $k => $v) $keywords[$k] = (int)$v; $codes = implode(",", $keywords); I am trying to figure out how i can modify this code to look for text and not an integer and still keep my code structure if at all possible. Any help would greatly be appreciated. Below is just more code in case you need it. if there is more code you need let me know Thanks again. // connect to the mysql database server. $connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error()); $selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error()); //trim whitespace from variable $searchcode = preg_replace('/\s+/', ' ', trim($_GET['search'])); //seperate multiple keywords into array space delimited $keywords = array_diff(explode(" ", $searchcode), array("")); if( !empty($searchcode) ) { foreach($keywords as $k => $v) $keywords[$k] = (int)$v; $codes = implode(",", $keywords); $searchcode_query = "SELECT * FROM contact_log"; //Store the results in a variable or die if query fails $result = mysql_query($searchcode_query) or die("Error executing MySQL query<br />".mysql_error()); $count = mysql_num_rows($result); } Quote Link to comment Share on other sites More sharing options...
aeafisme23 Posted February 19, 2008 Author Share Posted February 19, 2008 just a friendly *BUMP* Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 19, 2008 Share Posted February 19, 2008 SELECT * FROM `table` WHERE `search_field` LIKE '%search_string%'; % in a MySQL string represents a wildcard and matches zero or more characters. Quote Link to comment Share on other sites More sharing options...
aeafisme23 Posted February 19, 2008 Author Share Posted February 19, 2008 Awesome thanks, one quick question though, what do i do about this section: foreach($keywords as $k => $v) $keywords[$k] = (int)$v; $codes = implode(",", $keywords); Is it something i should just eliminate or keep in? I was thinking that somehow i had to define the (int) to text so when it does show my results and what i looked for it will not check for an integer and return an integer value but it will return a text value. Does this make sense ? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 19, 2008 Share Posted February 19, 2008 If $keywords is an array of strings then you want to drop the (int). The (int) converts the value that follow it into an integer. So here's a couple questions for you. How do you convert the string '54' to an int? Just drop the quotes, right? Easy enough. How do you convert the string 'WUSA' into an integer? Quote Link to comment 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.