php - strpos() function on mysql_fetch_array -
i have code fetching information mysql database in php , want compare $username variable information strpos() function...but doesn't work.... can do?
$username = $_get['username']; $connection = new db_database(); $res = $connection->select(); if ($res) { $output = ""; while ($row = mysql_fetch_array($res)) { if (strpos((string)$row['username'], $username)) { $output.=" " . $row["username"] . " "; } echo $output;
i 'm not sure why using strpos
instead of straight comparison ==
, code not work correctly if $row['username'] == $username
.
the reason in case strpos
return 0
, evaluates false
-- see giant red warning on documentation page.
Comments
Post a Comment