Mysql Or For Search (select Part Of String)
I am creating a search function and i want to select say only 100 characters (or pref. 40 words) before and after the returned phrase in the results. so far i am using:
$get = mysql_query("SELECT * FROM posts WHERE content LIKE '%".quote_smart($query)."%' ORDER BY $order") or die("Cannot search: ".mysql_error());
i tried to use SELECT id, title, tid, uid, LEFT(content, 50) FROM POSTS.... but the query returned none of the content? any ideas? Code:
View Complete Forum Thread with Replies
Related Forum Messages:
How Would You Search For A Part Of A Word In A Whole String Or Flatfile Line.
How would you search for a part of a word in a whole string or flatfile line. for example like: the user inputs tax or another word and if the input is part of a larger word like taxation then it will print the result. Im trying to create a search that will allow the user to input small words and it will search the whole file and if a string with that file is found it will print it.
View Replies !
Select Only Part Of Mysql Desc
I'm trying to select and display only part of the description from a mysql database. It will have a button below the partial display called "MORE" for them to view the whole description. I've already got everything as far as putting and pulling the info, just need to know how to crop it.
View Replies !
MySQL SELECT Statement - Search A Field In Table
I am trying to search a field in my table for more than one likeness. Can I create a query that says: PHP Code: <?php $query = "SELECT * FROM $table WHERE $search_field (LIKE '%$this%) || (LIKE '%$that%')"; ?> OR, should I just do two different query statements and concatenate the results?
View Replies !
Is There Any Way To Select A MySQL Row By The Length Of A String?
Since there's no forum where I can ask about MySQL, I'm guessing the next best one would be here. Is there any way to select a MySQL row by the length of a string? For example, let's say I have a table with three fields : ID, Name, and Comment. Essentially what I want to do is select rows where the length of Comment is greater than 50 characters.
View Replies !
Select A Number Of Words From A String In Mysql
I have a series of long documents stored in mysql rows. I am trying to figure out how to select a section of of one of those documents to be displayed on the web. Example. Document 2000 words. Query (or php) to select 500 words from the document. (sometime from word 1-to-500, but also sometimes from the middle of the string). Does anyone have any ideas on how to break these large chunks of data into smaller chunks? (I would ideally like to use a SQL query to speed things up, but whatever gets the job done...) .
View Replies !
Parse Part Of String (mid String Function ?)
Can someone tell me how to parse part of a string? I can use the following: <?php $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url); echo $text; ?> to get this result: "Your currently at /test.php " I just want to get "test.php " without the dash. I also need to parse out parts of other strings. I know how to use Mid(), Left(), and Right() in VB, but no clue for PHP.
View Replies !
String Search - Search A String Of Text & Return A TRUE Value.
I'm trying to do something pretty simple but I'm stuck on what function I need to use. Basically, I have a script where you can type a message and submit it. But I don't want people to use bad words, so if they do, it displays an error message. Example: $string = "Fudge off!" Let's say I don't like the word "fudge" if ( stringcontains('fudge', $string) { echo "No cussing!" } else { Post the string } Does that make sense? I'm basically trying to find some kind of search that will search a string of text looking for the word "fudge" and if it finds it, return a TRUE value. Does such a function exist?
View Replies !
How To Search Strings Escaped By Mysql Real Escape String()?
I am currently developing an article script and there are Titles and Contents. To prevent sql injection, people say we must use mysql_real_escape_string(). So let's say if there is a Title that says "My Friend's best friend", if I look into the MySQL table record, the text will be saved as "My Friend's best friend", where the apostrophe is escaped. Code:
View Replies !
Search By Any Part Of A User Name
What should I modify in this script to do a search by any part of a user name and NOT by the whole username: <? $rs=@mysql_query("select * from usrinfo where UserName='$username'"); while ($ro=@mysql_fetch_array($rs)){ echo $ro[UserName]; } ?> ...
View Replies !
Search Part Values
I am trying to search part values from a mysql table. lets say I have field1 with a value of "abc123" a user enters "ab" how do I match up my user input to the db field. I use str_replace(" ","",FIELDNAME) in my SQL query, Match(Field1) AGAINST ('Val*' IN BOOLEAN MODE)
View Replies !
Getting Part Of A String
What I am attempting is to retrive part of a string, the string comes from TEXT field in mysql db using mysql_fetch_row. It is an article, in the article there is flags like for example [image]img=34,align=left[/image]. Now I would like to retrive the [image]img=%[/image] part to be able to use the wildcarded number for a database query to get the image link and image comment then giving it all a proper html formatting. After that, I replace [image]img=%[/image] in the original string with the newly formatted html.
View Replies !
Get Part Of A String
if I could use php and get certain parts of a string like $string: = "<table><tr><td>Name</td><td>Desithugg</td></tr></table>"; Would it be possiable to use something like preg match to get only that part Desithugg into another string like $name. So I want to get the part between <td>Name</td><td> and </td></tr>. If it's possiable can anyone give me an example. I tried looking at the manual but didn't quite get it.
View Replies !
Using Only Part Of A String
Pulling data from old DB to new DB. One field is text for an article, I need to pull it and only get part of it for a new summary field. How can I get just part, say 1 or 2 paragraphs out of the string?
View Replies !
Replacing Part Of A String
I am using the command ereg_replace() to replace " with ' . For fast web pages, I use Microsoft Frontpage and it has everything use ". I have to change them all to use ' . The code is writen and it works, sort of. It has some text displayed at the end I don't want. Here is the my code:
View Replies !
Replace Part Of String
just found a problem with part of my project if a ' is present then it screws up the sql query- so, i need toget rid of it, would the best way be to, use regex, and see if string a contains a ' || string b etc and if so, use str_replace("'","",$string);
View Replies !
Retrieve Part Of The String
If I have a string $string = "SELECT * FROM TABLE WHERE AGE > 0 ORDER BY NAME"; how would I retrieve part of the string before 'ORDER'; i want this part 'SELECT * FROM TABLE WHERE AGE > 0' if i use strstr($string,"ORDER"), this retrieves 'ORDER BY NAME' is there an opposite function of strstr()?
View Replies !
Return Part Of String
I am currently looking through the PHP manual for a way to return part of a string, e.g. $str = '(number:1)' $i = preg_return(number:[0-9]*, $str); which would echo me back a "1". strstr() would kind of have been nice, but then I would get the last parenthesis also. One way I could do this is using preg_replace and kind of remove all other strings and only return the number, but I feel that there should be a "easier" (read: better) way to do this.
View Replies !
How Can I Get The Middle Part Of A String?
If I have a string such as.... $a = "Start Middle End"; How can I extract "Middle" out of this and put it into $b? I want to do it by searching for the first space and stripping it out of $a. Then I will be left with "Middle End". Then I want to search for the first space and strip it and anything after that and be left with "Middle".
View Replies !
Trim Part Of A String
I would like to trim part of a string which looks like this: $input = "This part should stay (Bracket) (Bracket2) (Bracket3)"; $output = "This part should stay"; Second and third brackets do appear sometimes and sometimes not. I need the part before the first bracket and leave the space char out. How can I do this?
View Replies !
Stripping Off Part Of A String
I really read all about preg_replace and other pregs and strs but cant actually do this one: $path = "/var/www/help/index.php"; the path can differ, there are more or less dirs but there always is "/var/www" part and I want to strip it off and get whatever comes after that. I really cant understand these preg_replace parameters like ("/(</?)(w+)([^>]*>)/e", So could anyone help me in the above specific example ?
View Replies !
String As Part Of A Variable Name
This has been bugging me for a while now! I'm trying to figure out a way to make a string part of a variable name. I know you can do this: PHP Code: $var = 'string' $$var = 'something' echo $string; I'd like to concatenate the term 'string' with something else, such as: PHP Code: $var = 'string' $$var._test = 'something' echo $string_test;
View Replies !
Find Part Of A String
I am an ASP guy who has been converting to PHP. Anyway, I'm having a problem figuring out how to find part of a string. What I am trying to do is to list any file that starts with "info". So I've got a while loop that will show all the files, but now I'm trying to figure out how to display only the files that start with "info". In ASP it would be like this: If Left(strFileName, 4) = "info" Then Response.Write(strFileName & "<br>") End If Does PHP have a function like this? In the example above it reads the first "4" characters in the string strFileName and compairs it to "info".
View Replies !
Replace Part Of String In Between Two Other Parts?
I'm trying to do is an str_replace or something within only a set of other strings. What I'm doing with some text that I put into a database is added a <br> whenever the ASCI character 10 (carraige return) comes up. It's like this. $text = eregi_replace(10, "<BR>", $text); what keeps happening though, is that when I make an HTML table in the text, it adds a <br> to that too, and since it's inside the table, it just adds the newline to outside of the table or something and screws everything up. So, what I want to do is only have it replace the newline with a <br> if it isn't inside of a <table></table> string. I've been all over the PHP documentation and have yet to see something that might work.
View Replies !
RegExp That Looks For A String And Only Replaced Part Of It...
I'm after a regular expression that looks through a string for a certain code, and then replaces part of that code with some markup: So look in this string: this text contains (T123) a code. And become this string this text contains (T<a href="?a=123">T123</a>) a code. The main problem I'm having is that my regexp replaces the whole match, including the T: $pattern='(T[0-9]{3})' $replace='<a href="?a=1">1</a>' This results in a hyperlink "?a=T123" when I want ?a=123
View Replies !
Copying Variable Part Of A String
I have strings like these: $line = "Item <name> xxx stock, costs yyy and will sell for amount zzz"; Problem is <name> can consist of 1..n words. Most items are single words, but some are up to 8 in my example, and there are is no set maximum (well, max is 80 chars I believe, have to look in the stock db, not too relevant I think) I found this out the hard way. I thought I was clever (never do that again) by doing this: $words = explode (" ", $line); $itemname = $words [1]; This only works for single-word names. Now I want to create or use an existing function that simply copies everything between Item and the first numerical substr. The function then should look like: $itemname = GetSubStr ("Item" , <numerical> , $line); <numerical> should be a template of some sort I think.
View Replies !
How To Get A Part Of String Using An Iterative Method
Assuming I have the following line from a text file: define ('THIS_IS_A_TITLE', 'My data for this title'); which I load into a variable, therefore $line = define ('THIS_IS_A_TITLE', 'My data for this title') My purpose is to get two variables from that like $title = THIS_IS_A_TITLE $data = My data for this title How would you do that? I thought of counting the ' characters, then $title begins after the 1st ' and ends before the 2nd, whilst $data begins after the 3rd ' and ends before the 4th. But maybe there is a more elegant way. Any ideas?
View Replies !
Replace Part Of A String With Wildcard?
i replace everything betwwen two different characters: <font face='Verdana, Arial, Helvetica, sans-serif' color=#FFFFFF size=3> or <font face='sans-serif' color=#0f0f0f size=3> so all the font tags will change to <font size=1> could i do "[<font] .*. [>]", "<font size=1>"
View Replies !
Substr :: Extract Part Of A String
Say i wanted to extract part of a string with the substr command i need say 1.mickeymouse-home how would i extract just mickeymouse and then extract home after wards $string = 1.mickeymouse-home; substr($string1,strpos($string, "-")+1); - i thought this would get me everything after "-"
View Replies !
Storing Part Of A String In A New Variable
I have a string (usually a url as it happens) which I need to get a certain part of and then store it in a variable. i.e. my strings are like this: "http://www.foo.com/directory/add/00102020/do.php?stuff" "http://www.foo.com/directory/add/00301090/do.php?stuff" So basically the URL or String are the same except for the numbers change. It is the numbers I want to store in a new variable. I think I need to use regular expressions and preg_replace but just can't get my head around how!.
View Replies !
Search String Delimited In Another String
I have a string (Website referrer). Example: http://www.google.com/search?q=MY STRING HERE&hl=tl&client=firefox-a&channel=s&rls=org.mozilla:en-US:official&hs=dXZ&start=30&sa=N I need to extract the keywords searched (example in the above case: "MY STRING HERE"). I think I need the string between "q=" and the next appearing "&". How can I do this?
View Replies !
Ordering Mysql Request By Part Of A Key
I have a database of kennels. One page lists the kennels alphabetically by kennel name. I have a field for kennel name and an index with kennel name as the only field. Some of the kennels have the word "The" as the first word in the name and they do not want to be listed alphabetically by "The..." Is there a way that I can request that mysql ignore "The" in a kennel name when ordering it or must I create a new field for the ordering and remove the "The" from the kennel name for that field ?
View Replies !
Selecting First Part Of Postcode MySQL
I have a database of London postcodes. They are in the format: xx xxx, xxx xxx or xxxx xxx I need to select the first part of the postcode (ie. up to the space) Can someone please advise me on how this can be accomplished??
View Replies !
Selecting Only Part Of MYSQL Result
Ok I am writting a script where the first time you look at something it inserts a word, on that shouldnt be mistakenly typed in. The script is pulling from a MySQL DB. I need to have a way to check for the word and if present not readd the word so it doesnt replicate over and over again. echo "<TEXTAREA name="comments" rows="8" cols="20">$displaycall[9] TheWord:</TEXTAREA>"; What is happening right now every time this updated it adds TheWord: over and over again. Any ideas how to check inside of the $displaycall[9] for TheWord:?
View Replies !
Populate Drop Down From Mysql With Php Part II
I have this working sort of, but I still can't figure out why it is skipping the "uniqid" field. Does it not work if the field is an auto_incrementing INT value or something? Also, where do I add the "form action" elements to this code to allow the user to actually submit after selecting? ....
View Replies !
Multiple Select Box Search Queries
I am trying to create an elegant query together with a multiple select box, tbl_level linked by a foreign key. Sample code below: $sql = "SELECT DISTINCT Firstname,.... FROM .... "; //conditional statement to determine whether WHERE clause is needed if($_POST["FirstName"] != "" { $sql .= "WHERE "; if($_POST["Firstname"] != "") { $sql .= "Firstname LIKE "".addslashes($_POST["Firstname"]).""" } //select box entries array Level if($_POST["Level"] != ""){ $i=0;$query.="( "; foreach ($_POST["Level"] as $val{ if ($i >0){$query.= " AND ";} $query .= "tbl_level.LevelCatID LIKE $val "; $i=1;} $query.=" )"; $query.= " AND tbl_name.NameID = tbl_level.NameID"; } //query database I can't use this as only a single Level select selection works, if user selects more , I can' t search the Level column for 2nd input from the select box using this. I am trying to avoid too many calls to the database, As I have several multiple select options for user to input for searching.Am trying to call single complex query at the end of code.
View Replies !
Displaying Select Information From XML Search Results
I am new to both php and xml. I have a school assignment to update an existing php-based website where I have to display search results from an online library. I can use a url search which returns an XML file that includes tags such as position, title, url, description, date, etc. I only want to display the title, url (preferably the title should be a link to the url), and description for all of the results on my website's search results (different template as well). What classes/functions are available to help me do this? I would appreciate any guidance as well as links to online tutorials etc. that would point me in the right direction. I have read about the general aspects of php, and I have experience with Java and C; but I don't know about xml at all. By the way, the website is running on the school server and has php version 4. I don't think I'll be able to install php 5 but I can probably upload some helper files or something.
View Replies !
Advanced Search W/ Multi-Select Array
I'm working on a site that deals with a MySQL database of stores across the country. I'm implementing an 'advanced search' section, and I can't for the life of me figure out how to handle queries that are derived of variables coming from multi-select lists. It seems like it would be an obvious thing, just going off the sheer ubiquity of similar search pages out there, but I just can't seem to come up with the logic behind it. Code:
View Replies !
|