Hi everyone,

Scenario: Getting two variables from an HTML form ('id' and 'last_name') and I'm querying MySQL to get the first 3 letters of a field (last name) based on input 'last_name' where id is based on 'id'.

What I Did: I looked up the MySQL manual, found the LEFT() string function at: http://www.mysql.com/doc/en/String_functions.html, and then wrote the query as such:

$query = "SELECT LEFT('$last_name', 3)FROM sampleTable WHERE id='$id'";
$runQuery = mysql_query($query);
$rezultNUM = mysql_num_rows($runQuery);

if ($rezultNUM > 0)
{
echo "FOUND ITEM IN DB!";
}
else
{
echo "NOTHING FOUND!";
}

I checked this and it always returns "FOUND ITEM IN DB". Anyone have a clue as to what's going on?

Thanks a bunch.

Ilir.

    I can't tell what you are trying to do from your code. Does $id contain the id of a row? If so you will get the first three letters of whatever happens to be in php variable $last_name. You never get any fields from the database. And your query search criteria does not have anything to do with $last_name, only $id.

      Write a Reply...