Jump to content

[SOLVED] omitting an output if value is NULL.


vomitbomb

Recommended Posts

Put this code together so it omits entries if a value hasn't been put in.

It's not working and I'm getting:

Parse error: syntax error, unexpected '.' in C:\htdocs\showorders.php on line 19

 

$sql = "SELECT * FROM orders WHERE lname='$search'";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array( $result );

if(.$row['fname'] != NULL){
echo "Name: ".$row['fname'];
}

 

Anyone know another way I can do this?

that is because you have period before the $row

 

Try this:

$sql = "SELECT * FROM orders WHERE lname='$search'";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array( $result );

if($row['fname'] != NULL){
echo "Name: ".$row['fname'];
}

It's simply PHP's concatenation character.

 

PHP:

"String" . "String" makes StringString

Javascript:

"String" + "String" makes StringString

 

And so on...  It's just the symbol in PHP that tells it to stick two strings together.  Kind of ironic now that I think about it.  A symbol which usually means end a sentence being used to stick two things together....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.