|
Posted by Jerim79 on 11/21/06 16:14
Jerim79 wrote:
> I am working on a script that will query a database for a FNAME/LNAME
> combo. If it finds the combo, I need it to do one set of instructions.
> If it doesn't find it, I need it to do something else. What I can't
> figure out is what variable to check against. Here is what I have for
> the relevant part of the script:
>
> $connection = mysql_connect($hostname, $username, $password);
> mysql_select_db($databasename) or die ("Cannot connect to database"
> .mysql_error());
> $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
> NAME=('$LName')";
> $result = mysql_query($query) or die('Query failed: ' . mysql_error());
> mysql_close($connection);
>
> I tried checking the value of $result to see if it changed depending on
> whether or not it found the selection. It does not. I just can't figure
> out what to use for:
>
> if (some expression){
> perform this code
> }
> else{
> do this
> }
I guess I could load the results into an array using fetchrow(), and
then check to see if it is NULL or contains data. If it is NULL, then
it didn't find it and I can do one set of instructions. If it is not
NULL, I can do another set of instructions. I am not sure that is the
best way to do it though. I would think that $result would change on
based on finding it or not, and I could just easily check against
$result.
Navigation:
[Reply to this message]
|