This is pretty simple code to look up a user in a MySQL database. if the user is there it returns exactly what it should. If the search form (from another page) is empty it does what it is supposed to do (not shown in this code). If the search name is not found in the database, I get no output, not the wanted "printf( 'The Associate was not found in the database.' );", or anything. I have tried several different things to do the "if ( !($row) )" to no avail. It has to be simple, but for the life of me I cannot figure it out.
Please help.
Rocco
BTW, I am new at this...
$link = mysql_connect( 'server', 'user', 'password' ) or die( 'I cannot connect to the database because: '.mysql_error() );
mysql_select_db( 'db_newcal', $link ) or die( 'Cannot select the database because: '.mysql_error() );
$userLookup = 'SELECT * ';
$userLookup .= 'FROM tb_associates ';
$userLookup .= 'WHERE lastName = "'.$user_name.'" LIMIT 0, 30';
$result = mysql_query( $userLookup, $link );
while ( $row = mysql_fetch_array($result) ) :
if ( !($row) ) {
printf( 'The Associate was not found in the database.' );
} else {
?>
<table>
<tr>
<td><b>First Name: </b><?php printf( $row[ 'firstName' ] ); ?></td>
</tr>
<tr>
<td><b>Last Name: </b><?php printf( $row[ 'lastName' ] ); ?></td>
</tr>
<tr>
<td><img src="images/AssociatePictures/<?php printf( $row[ 'firstName' ] ); ?> <?php printf( $row[ 'lastName' ] ); ?>.JPG" /></td>
</tr>
</table>
<?php
}
endwhile;
mysql_free_result($result);