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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.