Page 1 of 1

Query within a $token of array: hello|today|this

Posted: Fri Jun 10, 2011 8:41 am
by simonmlewis

Code: Select all

<?php
$q=$_GET["q"];

include "dbconn.php";
$result = mysql_query ("SELECT id, wanted FROM admin WHERE wanted LIKE '%$q%'")or die(mysql_error());
while ($row = mysql_fetch_object($result))
{
  $string = $row->wanted;
  $token = strtok($string,"|");
  while($token)
    {    
    if (preg_match("/$token/i", "$q")) { echo "<a href='#' style='text-decoration: none' title='$token'>$token</a><br/>";
    $token = strtok("|");
    }}
} mysql_free_result($result);
mysql_close($sqlconn);
?>
This is producing nothing.
I am passing through "shred" for example, and if in the wanted field, it finds "shreddy|fred|sunny", it should then find that string, and then check that each $token is similar to what I have passed thru on $q.

But it won't. Can anyone see a problem with it?

Re: Query within a $token of array: hello|today|this

Posted: Sat Jun 11, 2011 2:11 pm
by getmizanur
it should be this

Code: Select all

$q = "shred";
$string = "shreddy|fred|sunny";
$token = strtok($string,"|");
while($token)
{
    if (preg_match("/$q/i", $token)) {
        echo "<a href='#' style='text-decoration: none' title='$token'>$token</a><br/>";
    }

    $token = strtok("|");
}