Jump to content

SQL Where clasue


adult.swim

Recommended Posts

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 parameter
if (!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]
Link to comment
https://forums.phpfreaks.com/topic/14353-sql-where-clasue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.