adult.swim Posted July 12, 2006 Share Posted July 12, 2006 I've just found the code I've been looking for that Uses PHP to search a MySQL database and return paged results.I've been modifying the code to fit the specifiactions that I need. My question is what is the significance of: \"%$trimmed%\"in the SQL Query. I dont know how the backslashs work, or what they mean in this context. If u know please explain, Thank You.[code=php:0]<?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable// rows to return$limit=10; // check for an empty string and display a message.if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; }// check for a search parameterif (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; }//connect to your database ** EDIT REQUIRED HERE **mysql_connect("localhost","username","password"); //(host, username, password)//specify database ** EDIT REQUIRED HERE **mysql_select_db("database") or die("Unable to select database"); //select which database we're using// Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL que[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14353-sql-where-clasue/ Share on other sites More sharing options...
zq29 Posted July 12, 2006 Share Posted July 12, 2006 The backslashes in your example are used to escape the double quotes. Alternatively you'd have:[code=php:0]$query = "select * from the_table where 1st_field like '%$trimmed%' order by 1st_field";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14353-sql-where-clasue/#findComment-56636 Share on other sites More sharing options...
Daniel0 Posted July 12, 2006 Share Posted July 12, 2006 I don't think you can use double-quotes in SQL. So try changing the query to: [code]select * from the_table where 1st_field like '%$trimmed%' order by 1st_field[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14353-sql-where-clasue/#findComment-56637 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.