/    Sign up×
Community /Pin to ProfileBookmark

problem with mysql database vs text comparison

Hi,

I would need to receive a list of text from the user and compare each entry in the list with the entries in the mySQL database. However, my code doesn’t seem to run properly:

[code=php]
<?
include(‘common.php’);
$fp = $_POST[‘input’];
$conn=mysql_connect($_cfg[‘host’],$_cfg[‘user’],$_cfg[‘pass’]);
mysql_select_db($_cfg[‘db’],$conn);

$fp = str_replace(“n”, ” “, $fp);

$data = explode(” “, $fp);

$foundlist = “”;
$notfoundlist = “”;

$c = 0;

while ($c < count($data)) {
$res=mysql_query(‘SELECT * FROM `list` WHERE `word`=”‘.$data[$c].'”‘,$conn) or die(mysql_error());
if (mysql_num_rows($res)<1)
{
$notfoundlist = $notfoundlist . “n” . $data[$c];
}
else
{
$foundlist = $foundlist . “n” . $data[$c];
}
$c++;
}
?>
[/code]

Only the last entry in the list will be processed properly. Can someone help?

Thanks.

Daniel

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsOct 16.2004 — try this query instead:"SELECT * FROM <span><code>list</code></span> WHERE <span><code>word</code></span> LIKE '%{$data[$c]}%'"
×

Success!

Help @danlohye spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...