Please help with this if you can

My example code below is part of a table that echos several fields, for this field I need to echo the text of the field which the below example code now does, but i need to make it state N/A if the field is Null also which i guess would be with a if/else command but got no idea how to fit it in with the current code

echo $row['model'];
	echo "</td><td>";

Thanks for your help and time

echo is_null($row['model']) ? "N/A" : $row['model'];

This is an inline if/else statement. If the "is_null" condition is satisfied, the output will be "N/A", else the value of your array item.

If the output is a number you could also use $row > 0 instead of is_null($row).

Let us know if this helps :)

thanks for your help

it does change to null but all are changed to null

Really sorry it does work, my fault. Thanks for your very quick help

Otherwise can echo with if else condition

if ($row['model']=="")
{
echo "N/A";
}
else
{
echo $row['model'];
}

Yes I did think of that one but the poster stipulated that the value returned would be NULL (NULL) rather than an empty string (""). For a more complete statement you might use something like:

if (!isset($row['model']) || $row['model'] == "" || $row['model'] === FALSE || $row['model'] === NULL || $row['model'] === 0)
{
    echo "N\A";
}
else
{
    echo $row['model'];
}

Depends upon the data types you're working with, but PHP tends to be pretty smart (or dumb, depends who you ask!).

The code in my first post is cleaner but less comprehensive, if it works (after thorough testing!) use it.

Remember to rep posts ;p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.