Jump to content

LIKE problem *FIXED*


Yesideez

Recommended Posts

First, here's some code:
[code]  switch ($searchrule) {
    case 1:$rulemysql="LIKE '%".$usrsearch."'";break;
    case 2:$rulemysql="LIKE '".$usrsearch."%'";break;
    case 3:$rulemysql="LIKE '".$usrsearch."'";break;
    default:$rulemysql="LIKE '%".$usrsearch."%'";
  }[/code]
[code]  $resultshtml="";
  if ($flagpowercodes) {
    $resultshtml.='<strong>Power Codes</strong><br />'."\n";
    $found=countmatches("`matches` FROM powercodes WHERE (`area` ".$rulemysql.") OR (`counties` ".$rulemysql.") ORDER BY `codeid` ASC");
    if ($found>0) {
      $resulthtml='<table cellspacing="0" cellpadding="2" class="outside">'."\n".'<tr class="tbltr"><td class="tblhdr">Area</td><td class="tblhdr">Counties</td><td class="tblhdr">Code</td><td class="tblhdr" width="62">Times</td></tr>'."\n";
      $resulthtml.='<tr class="tbltr"><td class="gtext">Found: '.$found.'</td></tr>'."\n".'</table>'."\n";
    } else {
      $resultshtml.='Nothing found.'."\n";
    }
  }[/code]
[code]  function countmatches($query) {
    echo "SELECT COUNT(*) AS ".$query."<br />";
    $fetch=mysql_fetch_array(mysql_query("SELECT COUNT(*) AS ".$query));
    return intval($fetch['matches']);
  }[/code]
Here's a sample of what the query looks like:
[code]SELECT COUNT(*) AS `matches` FROM `powercodes` WHERE (`area` LIKE '%london%') OR (`counties` LIKE '%london%') ORDER BY `codeid` ASC[/code]

If I omit the OR and the second condition I get 3 returned but as it is now, this gives nothing no matter what I look for. Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/27701-like-problem-fixed/
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.