Search A Column Within My MySQL Database For Matches/partial Matches
I have built a form on a page that points to ProcessForm.php (The form has just one text entry field).
At ProcessForm.php, I am trying to put the php code on the page that will take what was entered by the user and search a column within my MySQL database for matches/partial matches. The aim is to then display found matches on a HTML page, basically similar to the way Kelkoo would work when you search for a product. Code:
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Search Alike Matches
I put a field on my homepage for users to be able to type in two or three word phrases and products will display simalar results. Here is my current code: $conn = db_connect(); $sql = "SELECT * FROM books "; $sql .= "WHERE `No` LIKE '%$mysearch%' "; $sql .= "OR `description` LIKE '%$mysearch%' "; $sql .= "OR `title` LIKE '%$mysearch%' "; $sql .= "OR `author` LIKE '%$mysearch%' "; $sql .= "OR `isbn` LIKE '%$mysearch%' "; Is their something I might could use in place of this that might would be a little more leniant? This code above is a little to strict.
View Replies !
View Related
Search Array Instead Of File For Matches
what I want to do is search by putting the file an array so I can page through using an offset. I have it all working except for this snipplet that is below I have searched for something that will work with no cigar. I my file is in this format. 100012|billybob|billybob@aol.com|3/10/2003|000-555-1212| I want to beable to do a partial match like with (preg_match("/" . $Searchstring . "/", $line))and (preg_match("/^$Searchstring/i",$line)) If I just use the plain $Searchstring withouth the jazz I need a exact match I don't want that. PHP Code:
View Replies !
View Related
Query The Database At The Beginning Of Every Page And Make Sure The Password Matches The Username?
I've got a login page that accepts a username and password. The action script for the form on the login page encrypts the password and then queries a database to see if the username and password jive. If they do, the user is "logged in"; that is, a session is started (I'm using php 4) and the variables "username" and "password" are registered along with some other vars. In subsequent pages that require authentication, I include a file that looks like this: if( !($PHPSESSID && $username && $password) ) { // User has not been logged in...go to login page header("Location: ${basename}login.php"); exit;} Is that enough? Or do I need to query the database at the beginning of every page and make sure the password matches the username? I didn't do that to begin with because of the overhead involved.
View Replies !
View Related
Counting Matches
This is really more of a MySQL question than PHP per se, but the only MySQL group my newserver carries seems to be pretty quiet, so I thought I'd ask here. What I am trying to do is determine the number of terms which match a field in the database where an initial string of multiple words has been broken up into single terms and the SQL statement is built by looping through each term separately, something like this: $original_string = "this is a test string" // code to remove stop words/common terms leaves $trimmed = "this test string" // this is then exploded at the space into an array of its constituent words. This array is then looped over to pass each word to an SQL query thus $SQL = "select * from main where" while(there are terms){ $SQL .= "Title like '%" . $term . "%' OR" } // this would lead, using the above example, to an SQL query which looks like this: $SQL = "SELECT * FROM main WHERE Title like '%this%' OR Title like '%test%' OR Title like '%string%' What I need to do is to check how many of the terms actually match something. Is there any way, either in MySQL or with the result array in PHP, to determine this?
View Replies !
View Related
Date Matches
Well i made it so when somebody clicks a certain button it logs the date in a database then it pulls it out when needed and matches it to todays date and if it matches it displays Today, instead of the date. Im trying to do the same thing but for Yesterday, so i need to match the date in the database to the date of yesterday. How do i find the date then take away a day? Im using date('F d, Y'); btw... i need to take a day away but im not sure how.
View Replies !
View Related
Get Regex Matches
I got a text: $text = "Blah... user1@domain1.com ...blah.... user2@domain2.com ..."; How do I get hold of the e-mail addresses: user1@domain1.com, user2@domain2.com, ... using regex? How to do it with php? UPDATE: preg_match_all("/(w|.)*@w*.w*/", $text, $match); $match contains all matches, all e-mail addresses in $text.
View Replies !
View Related
'do While' Query Row Matches
I have a 'do while' repeat region that returns new site registrants. This returns results as: <?php echo $row_Main['MemID']; ?> //primary id Now what I need to do is add a column on the row, and place a 2nd query that will match on this same value. I'm doing this to make conditional echoes -- its an admin panel, and I simply want to echo hyperlinks for tasks to perform on each site registrant. When the 2nd query evaluates !=='' I'll echo 'done', if not, link to a form to perform the referred to task. Roughly within the repeat col row: if (2nd query !=='') {echo 'done'} else{echo hyperlink to do this} How can $row_Main['MemID']; value be matched on within seperate queries that are placed within its repeat region? Dreamweaver runtime variable: shouldn't Post pull this if its already being echoed on the row? $HTTP_POST_VARS($row_Main['MemID'])
View Replies !
View Related
2 Possible Preg Matches
PHP Code: $html = file_get_contents("http://mycrib.net/?pageid=mycrib.member.profile&ID=$_POST[intMSUserId]"); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â preg_match("/<title>MyCrib: (.*) Profile</title>/", $html, $msname); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â preg_match("/([d,]+) friend(s)/", $html, $msfc); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â preg_match("/<IMG SRC="(.*)" class="image_default" border="0">/", $html, $msimg); This works flawlessly except the image match sometime the image match needs to use this instead PHP Code: preg_match("/<IMG SRC='(.*)' class='image_default' border=Ɔ'>/", $html, $msimg);.
View Replies !
View Related
Ereg Matches The First Occurence
I have a little problem with ereg (eregi) in PHP - in some cases it behaves differently than I expect and I don`t know if my expectations are strange or there is any "syntax subtlety" I have missed. I want to find a value for key1 in string: key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3][EOT] and I use an ereg pattern ereg("key1=>([[:print:][:space:]]*)[EOT]",$line,$regs); unfortunately ereg match differs from "value_of key1", which I wanted to receive. Ereg finds the last apperance of [EOT] in string $line and the value of $regs[1] is "key1=>value_of key1[EOT]key2=>other_value[EOT]key3=>value[3]" Can I achieve an effect, that ereg matches the first occurence of [EOT] and as a result I`'ll get "value_of key1" as a result?
View Replies !
View Related
Creating Matches In A Series
I have a difficult one for you Using PHP and storing the matches in a MySQL database. Table like (matchid,hometeam,awayteam,date) If I have four teams and want each of those four teams to meet the other three teams twice within a series. One time as home team and once as away team. Another condition: A team can not play two matches on the same day. Example: Team1 (home) meets Team2 (away) on day 1. Team3 (home) meets Team 4 (away) on day 1. Team 2 meets Team1 on day 2. Team 4 meets Team3 on day 2. Team 1 meets Team3 on day 3. Team 2 meets Team4 on day 3. and so on... How do I write the loop(?) which will generate the matches on the correct day and without any collisions.
View Replies !
View Related
Combining 2 Preg Matches.
I have a function which validates a string using preg match. A part looks like if( !preg_match( '/^([a-z0-9]+(([a-z0-9_-]*)?[a-z0-9])?)$/', $string ) || preg_match( '/(--|__)+/' ,$string) ) { i wonder how i could combine those two into one ... I tried a few different options of putting the second match into the first one, using things like [^__]+ etc, but nothing worked for me. it should prevent double (or more) dashes or underscores behind each other. hello-there = ok hello--there != ok
View Replies !
View Related
Highlighting Regex Matches
I'm trying to achieve the following: start form entry user enters form data and submits ($form_data) preg_match_all data for $pattern, store matches in $match_arr if one or more matches display string back to user, with matched substrings in different color/emphasis start form entry again else continue my initial solution to recontructing the string: // if 1 match preg_replace ($pattern,'<em>'.$match_arr[0][0].'</em>',$form_data,1); // if multiple matches preg_replace ($pattern,'<em>'.$match_arr[0].'</em>',$form_data,-1); ...but the latter doesn't work the way I hoped. When the replace var is an array $pattern also must be an array for preg_replace to use the different array values in $replace. Any ideas how to get around this problem in an elegant manner? Or an alternative solution altogether? I searched for a function/solution that tells me at which position preg_match_all() found a match, so I can avoid the preg_replace altogether, but I haven't found any.
View Replies !
View Related
Quantifier Matches 0 Or More Times
quantifier matches 0 or more times. is this normal to be true or false preg_match ("/tras*hformers/" , "trashforsmers"); // FALSE (tutorial says it should be true preg_match ("/tras*hformers/" , "trashformersss"); // TRUE i'm wondering couse i found one tutorial, and now when i test it looks like it's wrong. i guess the whole pattern must be true AND then after the pattern if any 's' were found it will also be true.
View Replies !
View Related
Criteria Matches Array
I have an array (say $arr) containing all the valid ID's. I want to pull records from mysql where the id-field of mysql table matches from the array range. How do i do this? eg. $arr=array(5,12,19,23,68,98); Now, I want to pull records from mysql table (tablename Personal) whose personal_id present in $arr. $arr do not actually have fixed values neither in value nor in no. So, How to do this?
View Replies !
View Related
Create List Of Matches!
i list how many times a word appears in some text and create an array of them. so if the text contains 3 <a href='whatever'>whatever</a> i can create a list od the 3 results at the top; 1<a href='whatever'>whatever</a> 2<a href='whatever'>whatever</a> 3<a href='whatever'>whatever</a> search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here. search text goes here.
View Replies !
View Related
Counting Number Of Matches
I'm trying to return data from mysql database. I have over a thousand records and each record has a "type" field with values ranging from 1 to 9. I'm setting up an html table that has 9 cells and all I want to do is count the total amount of types. For example, there are 140 records as type 1, 300 records as type 2 etc.
View Replies !
View Related
Counting Matches In An Array?
I have form data coming in and a preg match statement. What I would like it to do is when the match is true, give me a total of true statements (got that), as well as count the like items. The array is matching true properly, example array: Code:
View Replies !
View Related
Php - Mysql - Search On Partial IP Address
I have a database that stores all the ip addresses of the machines on my network. One table consists of the ip address itself, and the second field is an ip_number (converted via the ip2long function in php). I could not find a way to search on the normal, dotted quad IP address notation, hence the ip_number field. I can easily search on this field when using the entire IP address, but would like to allow the user to enter partial IP addresses. Any ideas on how I can do this when I need to convert the IP address to an IP number to actually do the search?
View Replies !
View Related
Multiple Records Where One Field Matches
I need all of the records where the $topicID = 1,2,3,4 Here's what I have that's working off an array of checkboxes: $query = "SELECT * FROM expertise WHERE topicID = '$choice[0],$choice[1],$choice[2],$choice[3]'"; I know this is screwed up. The results are less than reliable. It appears to only pay attention to matches for $choice[0] and then lists results that don't match the other choices selected.
View Replies !
View Related
Counting Matches In Array, Part 2
$types = array(); foreach($flower[1] as $type) { $types[$type] += 1; } echo "<pre>"; print_r($types); echo "</pre> "; This worked great for counting the like items and I can echo out the new array details as planned. But then I had to go and want to get a bit more complex. Instead of just having 1 value to determine count, now i have 2. Code:
View Replies !
View Related
Better Ways Compare Strings: Exact Matches
I'm creating a lot of arrays. Some of the arrays carry words that get duplicated... For example: $aCities = {"Durham", "Raleigh", "Raleigh-Durham", "Salem", "Winston", "Winston-Salem" } I've been using stristr alot but that ends up meaning that I must take the arrays out of alphabetical order and in the end it complicates things on my part. I'll comparing it to the strcmp() function right at the moment but I ran into some difficulties with strcmp() a couple nights ago, along the lines of having to convert the strings in the array lower-case (all my arrays are currently stored in a ucwords() format). The dashes in the names also present a bit of a problem. The way I'm currently doing the comparisons... function GetCity($sSearchThis) { $aAllCities = GetAllCitiesArray(); // make sure parameter is lowercase $sSearchMe = strtolower($sSearchThis); foreach ($aAllCities as $sThisCity) { if (stristr($sSearchMe, $sThisCity) !== FALSE) { return($sThisCity); } // default to raleigh return("raleigh"); } What's the best way to accomplish this or is there a better way under the following conditions: (1) The item passed in IS a string (not an array). (2) A default string is always returned when no match is found. (3) The alphabetical order of the array must remain alphabetized. (4) The dashes are not required.
View Replies !
View Related
Find All The Matches In A Table Between 2 Specific Dates.
I need to find all the matches in a table between 2 specific dates. For example, on each date, a certain airplane may be available for hire. But there are 4 airplanes. So on any date, there could be 4 planes available. Sometimes 1 or 2 of them are booked and not available. What i would like is to do a query, between 2 date ranges, and find only those airplanes available for all the days (say someone wants to go on a 5 day trips). What I have, but isn't working is this: SELECT distinct t.tid FROM dates d,types t,planes p WHERE p.oid=d.oid AND d.timestamp>$start_day AND d.timestamp<$end_day AND p.oid=$flight_school_id AND t.max_persons>=$max_people AND d.tid=t.tid GROUP BY (t.tid) HAVING count(*) >= $nights ORDER BY d.timestamp ASC";
View Replies !
View Related
Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field: gameboy, nintendo, playstation and I do a search, I know I can use regexp to do something like: select * from categories where regexp 'gameboy,' Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.
View Replies !
View Related
How To Select Count From 2ndary Table On Matches In Primary Table?
I'm coming back after about a 4 year break, so even basic stuff is taking forever to re-learn - I have a feeling that this is going to be a dumb question. Any suggestions on the best way to: SELECT count(<other table entry id>) FROM <other table> WHERE <the entries in this table referencing other table id> = <entries in other table by other table entry id> Basically, I just want to construct multiple rows of data that say: "here's the details of a Topic, and there are 10 (or whatever) Entries for this Topic" It seems like it should be simple enough. Code:
View Replies !
View Related
Finding Matches In A Table And Then Moving That Match To Another Table?
Ok, I have a database that has a table called critiera in this table is to fields on is ID and the other is critiera. Now I want to filter out all the one that don't apple to the list and move the one that match to a different database. I know how to open a connection, close, select but I don't know how I would inside of a database use another one as the way to create the list of critieras....
View Replies !
View Related
How I Check That His Username Entered And Password Entered Matches That In The Db.
when my user goes to log in, i'm pondering how i check that his username entered and password entered matches that in the db. Heres what i wrote: $query = "SELECT * FROM Members WHERE loginName='$username' AND password='$password'"; $result= mysql_query($query); $check =mysql_num_rows($result); if($check < 0) { echo "Error: Username or password did not match! Please try again!"; }else{ echo "Successfully Logged in"; But that returns this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fantasy/public_html/loginprocess.php on line 15 .
View Replies !
View Related
Search For Keywords In A Single MySQL Column
I am looking for a quick and easy way to take user entered keywords in a search field and search through a field in my MySQL table for matching words. I will have a field in the database called "Keywords" and they will be separated by commas. I know I can use: $search_array = explode(" ",$searchwords); to parse their submitted search terms into individual words, and $keywords_array = explode(",",$keywords); to break out the database field into individual words as well. I just cant think of the easiest way to compare here. Am I on the right track or have I lost my mind?
View Replies !
View Related
Valid MySQL Database/table/column Name Regexp
regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? The user of my (hopefully to be opensourced) program has the ability to create database/table/column names on the fly. I'm aware of obvious characters such as ., [space], things like >, etc., which won't work, but haven't been able to source a definitive list, including having googled the MySQL site. Obviously certain characters need to be filtered out, as noted above, but I want to be as unrestrictive as possible; hence just [a-z]* isn't good enough because things like _ are acceptable. Ideally, I'd prefer a regexp that applies to _all_ vendors' databases, not just MySQL as I'm about to migrate the program to being database-independent, probably using PEAR DB, but even a MySQL-specific regexp would do the job. In the longer term, I plan some sort of entity conversion script so that theoretically any character could be used, using some sort of escaping mechanism probably.
View Replies !
View Related
Using PHP For Mysql Command (update Partial)
I have a table with a structure column of "product_attributes" that I want to do a mass update to with certain criteria. Basically if within product_attributes there are some rows with the following: Code: color_blue,color_pink,color_purple,color_black color_blue,color_pink,color_purple,color_white color_green,color_pink,color_purple,color_black color_blue,color_pink,color_purple,color_yellow Now I want to change all instances of color_purple to color_violet. So that it should now read: Code: color_blue,color_pink,color_violet,color_black color_blue,color_pink,color_violet,color_white color_green,color_pink,color_violet,color_black color_blue,color_pink,color_violet,color_yellow How would I do this without disturbing any of the other information within that table? Only the one word in all rows with "color_purple" in it?
View Replies !
View Related
MySQL Partial Selection Of A Field
I've spent the last few hours putting together an RSS generator for my company's web site. Basically what happens, is when someone submits a story, PHP exports a some formatted code into an XML file. Right now, I have the user create a description of their entry. What I would like to do, is simply select the first 10 words or so from their entry and use that as a description in my XML file. Is there any way, whether it be in my SELECT statement or otherwise, that I can make this happen? Any best practice ideas?
View Replies !
View Related
Search Tags In Mysql Database
I'm creating a website that lists snippits of online articles. As tagging these articles will be very important, I've created a database structure as below. I'm now implementing searching of these tags with the hope to sort potentially 1000's of matches by relevance on tags and on date (the newer the better). Before launching head first into this, can anyone point me in the way of a good tutorial specifically on tag searches. (I can find plenty of fulltext sytle search information, but not so much on tagging). Code:
View Replies !
View Related
Text Search In MySQL Database
I am wiriting a PHP program that allows users to search item in the MySQL database. The items may have Chinese in their name or desciption. A form is created to allow users to input the search string and then it is transfer to another script to search the MySQL database by GET. I find that some strings can be found but some are not. Is it related to the property of Chinese characters.
View Replies !
View Related
Create A Simlpe Mysql Database Search
Im trying to create a simlpe mysql database search. I have a database called "lever" and then a table called "faults" Inside the table i have the following titles: Incident School Person Summary I want a search field that uses the "incident" filed to display data only in that row. I would like it to be displayed on a html page. Is anyone able to help me with the code. Ive tried using some that have been suggested on the web but I cant seem to configure them correctly.
View Replies !
View Related
|