...

View Full Version : Resolved pulling info from a search



harkly
11-22-2010, 05:20 PM
Not sure how to explain this, so please bear with me.

I am trying to verify if a userName is in a query but not sure how to check for it. There can be one 2 names in the query and I need to check to see if one ($clientID) is in it.

user has to be logged in so $clientID is set

My code:


$sql = mysql_query("SELECT author FROM replies WHERE thread=$id");
while($r = mysql_fetch_array($sql)) {
$author=$r['author'];
}

if($author==$clientID){
echo "True";
}
else {
echo "False";
}



So $author is either one of 2 names, $clientID or whatever
so for example - the author table

$author
Jack
Jill
Jill
Jack
Jill

With Jack = $clientId

when I run the query it will be false because Jill comes up last, but I need it to be true because Jack was in it as well.

MattF
11-22-2010, 05:42 PM
Code your query correctly.



$sql = mysql_query('SELECT author FROM replies WHERE thread='.intval($id).' AND author=\''.mysql_real_escape_string($clientID).'\' LIMIT 1');

if (mysql_num_rows($sql))
{
[the author was found]
}
else
{
[the author was not found]
}


That's assuming that $id is an integer, btw. If it's alphanumeric, use the real_escape_string on that instead.

harkly
11-22-2010, 05:47 PM
That won't help with my search issue.

Looks like I need to search the array for the $clientID

Working on this right now


$sqlImage = mysql_query("SELECT author FROM replies WHERE thread=$id");
while($r = mysql_fetch_array($sqlImage)) {
$author=$r['author'];
$authorArray = array($author);

if(in_array($clientID, $authorArray)){
$result='true';}
else{
$result='false';
}
}

MattF
11-22-2010, 05:51 PM
That won't help with my search issue.

Why? If you work on the assumption that we're not pyschic and actually give a useful description of what you're trying to do, maybe you'll receive answers which are more relevant.

harkly
11-22-2010, 06:58 PM
Sorry, MattF, your code did work, I had another issue that was messing up the results.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum