Jump to content

PHP & MS Access - Line Break


SarahB12

Recommended Posts

Hey Guys!

 

I'm pulling records from an MS Access database and listing them using PHP and I'm running into an error that I can't seem to figure out.

 

Please see the code below:

if (trim($rs->Fields("Address") !="")) {echo "<br />".$rs->Fields("Address")->value;}

 

I want to skip the line if there isn't an address, but for some reason even if there isn't a record it still outputs a line break <br />.

 

Thanks for your help!

~ SarahB ~

 

Link to comment
https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/
Share on other sites

Well for one, you are trimming the whole statement, so it is just returning if the address trimmed properly.  For 2, you can try trimming it properly:

 

if (trim($rs->Fields("Address")) !="")

 

Or you can try using empty instead:

 

if (!empty($rs->Fields("Address")))

 

And see if that works. Let me know if either or does not work.

Hi premiso,

if (trim($rs->Fields("Address")) !="")

gives me the following error: PHP Catchable fatal error:  Object of class variant could not be converted to string

 

and,

if (!empty($rs->Fields("Address")))

gives me this error: PHP Fatal error:  Can't use method return value in write context

 

Thanks for the suggestions!

 

 

Eh, never worked with Access in PHP, so yea. Let me ask you this, have you tried it like so:

 

if ($rs->Fields("Address") !="")

 

And see if that worked for you? Technically you should not have to trim it unless someone messed with the data as I doubt PHP or Access (well not really access but yea) would add random whitespaces to a column...

Still no luck.

if (trim($rs->Fields("Address") !=""))

and

if ($rs->Fields("Address") !="")

display everything exactly the same.

 

I haven't worked with access and php together before, so we are in the same boat.

 

@JustLikeIcarus

if(sizeof($rs->Fields('Address')) != 0)...

gives me the following error: PHP Notice:  Object of class variant could not be converted to int

 

 

 

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.