LIKE to search within text fields

This is PHP4 Code! Simple Example foreach ($search_tags_array as $tag_word) { $sql = "SELECT indexer FROM videos WHERE indexer != '$vid' AND title LIKE '%$tag_word%'"; $query = @mysql_query($sql); while ($result1 = @mysql_fetch_array($query)) $tmp_result_search[] = $result1[‘indexer’]; } Multiple LIKE tests " WHERE (title LIKE '%$keyword%' OR tags LIKE '%$keyword%' OR description LIKE '%$keyword%')"

Read More

Manipulating Returned Results

$sql1 = "SELECT indexer, user_id, friends_id AS from_id, //Change result name to from_id 'friend' AS type, //For each record found add a result called 'type' containing 'friend' todays_date FROM friends WHERE friends_id = $user_id"; Outputting Results As A Comma Separated List (Or any character separated) $QueryString = "SELECT CONCAT_WS(',',SomeColumnName0,SomeColumnName1,SomeColumnName2) FROM MyTable WHERE SomeColumn = 12"; //"CONCAT_WS(','," […]

Read More

Case Sensitivity

Select is not case sensitive by default SELECT * FROM myTable WHERE ‘something’ = ‘Something’ = 1 To make it case sensitive use a select with binary SELECT * FROM myTable WHERE BINARY ‘something’ = ‘Something’ //or SELECT * FROM myTable WHERE ‘something’ = BINARY ‘Something’ = 0

Read More

JOIN to get results from 2 tables

Using JOIN to get results from two tables This is PHP4 Code! Example 1 Example 2 Using JOIN to get results from three tables This is PHP4 Code! Example 1 Using GROUP BY To Get One Row Per Match This is PHP4 Code! Note – when using GROUP BY, if you also use ORDER BY […]

Read More

.SELECT General

Object Oriented Style Does Record Exist Simple Get A Result Alternative with check for no result Get Each Row Returned Procedural Style Does Record Exist Simple Get A Result Get Each Row Returned Get Number Of Rows Returned Get Specific Columns Get each field as a variable named as the field Using OR Arguments Putting All […]

Read More

Querying Across Tables

This is PHP4 Code! Using IN Within A Normal SELECT Query You can select from within another tables results really easily like this: SqlCommand1->CommandText = "SELECT ProjectId \ FROM tblMyTable1 \ WHERE ProjectIsActive='TRUE' AND ProjectId IN (SELECT ProjectId FROM tblMyTable2 WHERE ProjectUsersAll='TRUE' OR UserId=@UserId) \ ORDER BY ProjectStartDate DESC"; Simple Find Name From Another Table […]

Read More

ORDER BY

Sorting Results Use this To Sort On Multiple Values ORDER BY With $wpdb->prepare ORDER BY and %s does not work with $wpdb->prepare, in our tests the following order by gets ignored: Whereas this works as expected. So it seems that $wpdb->prepare() adding single quotes around the inserted name field causes it to break. Date Order […]

Read More