Jump to content

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

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.