PHP - Case Sensitive Search
when the simple search script in the tutorials on this site searches my mySQL database it doesnt find results unless they are typed in the same case as the original entry. ie 'horse' does not find 'Horse'
is it some problem with my database table formats or do i need to add a bit of script to the search to solve it? Similar TutorialsHow do I make the username and password checking CASE SENSITIVE? $result=sprintf("SELECT * FROM db WHERE username = '%s' AND watchword ='%s'", mysql_real_escape_string($username), mysql_real_escape_string($password)); Thanks. Bickey. I need to make the following code work without case sensitivity. For example, if this was processed, I would like for $message to be changed from "Stupid is not a nice word. Ugly is not nice either." to "unintelligent is not a nice word. unattractive is not nice either." For my purposes, I don't care that the capitalization changes, I just need the $goodwords to be replaced with the $badwords regardless of capitalization. Any ideas here? Code: [Select] <?php $message = "Stupid is not a nice word. Ugly is not nice either."; $badwords = array("stupid", "ugly"); $goodwords = array("unintelligent", "unattractive" ); $message = str_replace($badwords, $goodwords, $message); ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=317710.0 I am using preg_replace to automatically bold "$word" when it appears. It will only replace the word when capitalized. How can I get it to replace the word without being case sensitive. Also could I also throw a link in? I tried and I get a syntax error. I'm guessing the links in PHP are different than HTML Here is my code <?php $find ="/$word/"; $replace ="<b>$word</b>"; Echo preg_replace ($find, $replace, $definition); ?> Thanks I have the auto suggestion script. While the user is typing, results are printed below (from the database). The results are printed with bold letters that are in the search. However, this leads to errors in capitalization. The letters are replaced by users' queries, instead of from the database. Example: Search word: PHP Results: PHPfreaks, PHP tutorials But in the database this is the records: "phpfreaks" and "php tutorials". This is a script that replaces search letters with bolded: Code: [Select] $search = clean($_POST["search"]); $fname=$row['name']; //Record from database $re_fname='<b>'.$search.'</b>'; //Replace with bold letter $final_fname = str_ireplace($search, $re_fname, $fname); How to do a script that bold letters, but as they were in the database, not from search input? Once again the php noob returns with another boggle..... I got my client search working, but when it searches the database, it is only searching case sensative, and its not searching partial words. like for example using last names, if i search for Angeleyezz it will find Angeleyezz, but if i search angeleyezz it wont find it, nor will it find it if i search it as angel, ang, eye, etc etc etc. same goes for all fields that i am searching, name, address, telephone number, city, etc. how do i change this? my form code is he Code: [Select] <form method="get" action="search_client_function.php"> <input type="text" name="search_term" value="search"> <input type="submit" name="search" value="search" /> </form> my search_client_function.php code is he Code: [Select] <?php $title = "Search Results"; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } include('includes/header.php'); mysql_select_db("terra_elegante_operations", $con); $searchfor = $_GET['search_term']; $query = "select * from client_information where concat (account_number,name_first,name_last,address,city,state,zipcode,telephone,telephone_alt,email) like \"%$searchfor%\""; $result = mysql_query($query) or die("Couldn't execute query"); ?> <br /><br /> <table border="2" cellspacing="0" cellpadding="3" width="960" bordercolor="#000000"> <tr bgcolor="#e6e6e6" align="center"> <td><font face="verdana" size="2" color="#000000"><b>Account Number</b></font></td><td><font face="verdana" size="2" color="#000000"><b>First Name</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Last Name</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Address</b></font></td><td><font face="verdana" size="2" color="#000000"><b>City</b></font></td><td><font face="verdana" size="2" color="#000000"><b>State</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Zipcode</b></td><td><font face="verdana" size="2" color="#000000"><b>Telephone #</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Telephone Alt</b></font></td> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td><font face="verdana" size="1" color="#000000"><?php echo $row['0'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['1'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['2'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['3'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['4'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['5'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['6'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['7'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['8'] ?></font></td> </tr> <?php } ?> </table> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <?php include('includes/footer.php'); ?> I know its a bit sloppy, but I'm a php noob =\ this is the only way i could get it to work lol. I have taken over a wordpress site that a web developer set up and he is no longer working with me so I cant get his help with it, I have a custom front page that has been pulling press releases that where posted previously and categorized as "press" I was asked to add a blog which I did by categorizing the post as "blog" In a nutshell, I now need the front page code to pull a mixture of both the "press" and "blog" each category has a numerical id so blog is 7 and press is 3 This is the current code that is in the page <?php query_posts('category_name=press&showposts=10&offset=0'); ?> I looked up wordpress support for this, and found this query_posts(array('category__in' => array(2,6))); How can I integrate this if possible with the top line so it pulls the newest posts from both categories? Any suggestions could REALLY help me out! Thanks! Hello, I am completely new to php so please forgive me ahead of time. I am trying to create a link button on a website for a client that only directs to a certain external website on certain days and hours. Specifically, this is a web radio button that the client only wants to link to the web radio site when their live broadcast is on the air during certain hours on the weekend (i.e. Sundays 8-10 PM). Any other time, the client wants the web radio button to link to a default page since the web radio station plays unrelated music all other hours of the week. Does anyone know the best way to create such a time sensitive link for a button on a webpage? Thanks. I am by no means a security expert, but I would like to know if storing MySQL database information in an environment variable would be a good or bad idea. What are your thoughts? hey guys im having a few problems with my query if anyone can please help...the two problems im having is
1.the total price returning as 00106. price = 100.00 and p_and_p = 6.00 in the database...im after a figure that looks like 106.00
2. @category will be a parameter like :category which will be binded to a value like 'al'l, 'videos', 'dvd's', but if the parameter is ALL i dont want to join my categories table allowing it to select all rows regardless of the category
any help, pointer would be truly appreciated...thank you
SELECT @category := 'Videos', i.item_id, i.title, i.price, i.p_and_p, SUM(i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id CASE @category != 'All' THEN LEFT JOIN categories c ON c.name = 'Videos' END CASE JOIN users u WHERE u.user_id = '7' AND MATCH (i.title, i.description) AGAINST ('bla' IN BOOLEAN MODE) AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW() GROUP BY i.i Hi, I have the following code: Code: [Select] case "Twitter"; echo 'Twitter gadget will show here'; break; I need to make it so it's like this: Code: [Select] case "Twitter" AND $member['top'] == "1" echo "Twitter Gadget will show here"; break; I need to add a IF onto the CASE is it possible? Thank you. The result pages is supposed to have pagination like google help me please
hi, i just wanted to know... $arr[0] $arr[1] $arr[2] also this $arr[1] would be called a value, but how are the numbers 0,1 and 2 called? are that keys? didn't know where else to post this question. can i do something like this? Code: [Select] <?php switch ($i) { case 0: echo "i equals 0";?> ////////////// html stuff //////// <?php break; case 1: echo "i equals 1"; ?> ///////////////////html stuff////////////// <?php break; case 2: echo "i equals 2"; ?> ////////////html stuff/////////////// <?php break; } ?> i've read and seen there are variations of what im trying to achieve but havent seen a exact example...what im trying to do is put a where clause in my query depending on if a set variable has a value
CASE WHEN (@category_id IS NOT NULL) THEN LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id JOIN categories c ON c.category_id = sc.category_id AND c.category_id = :category_id ENDis this possible or have i just got the syntax wrong somewhere...thank you guys My case statement is not working. What happened is that two students got a $markgrade of 61 and 67. So they both should get grade B but instead they both get Grade A. 1 student got 55 which should be grade C but gets grade A. why is it not following the switch statement? Code: [Select] function outputModule($moduleID, $moduleName, $sessionData) { if(!count($sessionData)) { return false; } $markTotal = 0; $markGrade = 0; $weightSession = 0; $grade = ""; $sessionsHTML = ''; switch($grade){ case ($markGrade >=70): $grade = 'A'; break; case ($markGrade >=60 && $markGrade <=69): $grade = 'B'; break; case ($markGrade >=50 && $markGrade <=59): $grade = 'C'; break; case ($markGrade >=40 && $markGrade <=49): $grade = 'D'; break; case ($markGrade >=30 && $markGrade <=39): $grade = 'E'; break; case ($markGrade >=0 && $markGrade <=29): $grade = 'F'; break; }; foreach($sessionData as $session) { $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} {$session['Mark']} {$session['SessionWeight']}%</p>\n"; $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); $weightSession += ($session['SessionWeight']); $markGrade = ($markTotal / $weightSession * 100); } $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} {$markTotal} {$markGrade} {$grade}</p>\n"; return $moduleHTML . $sessionsHTML; } I have this $str variable which say holds "String" and in my comparison I'm checking if it's content is "string" and it is supposed to return true but it isnt because of the case, how do I compare them without the case being an issue ? i want to make a simple forced lower case form but i got stuck on it
to begin with i want to everything user's write and submit convert to lowercase
am i using the right code? i'm not sure about using preg_match in this situation but i dont know what else to do don't be harsh with me i'm noob <?php if(isset($_GET['user'])&&!empty($_GET['user'])) { $user = $_GET['user']; if (preg_match('$englishUpperAlphabet'//English alphabet Upper case array//',$user)){ $user = mb_strtolower($user); echo $user; } else{ echo 'none'; }} ?> <form action="t.php" action="GET"> name: <input type="text" name="user" > <br> <input type="submit" value="submit" > </form> Hi everyone,
On our school website, we've got a page where students can do a quiz, and get feedback given to them, as to whether their answers are correct or incorrect.
The code echos the student response for each question, and the feedback, tick / cross is displayed in the adjacent column.
However, I've just changed the input box from a text field to a text area, and I've noticed a little quirk.
The student answer, after pressing submit, now displays in lower case. Is their any way I can echo their answer, exactly as they input it.
Here is the relevant code:
<textarea name="user_answer_<?=$row_counter?>" cols="40" rows="2" /><?=$userAnswer?></textarea>Thanks for your time, Dave Is there a way to change the statement below so that it ignores case sensitivity of the variable? for instance, the statement would be true if $category == 'Admissions', 'ADMISSIONS', 'admissions', etc.
For some reason I'm having the worst time finding this via google search and know y'all will be able to help!
if ($category == 'Admissions') { echo ' <a href="#">-Forms</a><br /> <a href="#">-Tuition</a><br />'; } ?>Thanks! |