SarahB12 Posted December 2, 2009 Share Posted December 2, 2009 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 ~ Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/ Share on other sites More sharing options...
premiso Posted December 2, 2009 Share Posted December 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969819 Share on other sites More sharing options...
SarahB12 Posted December 2, 2009 Author Share Posted December 2, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969825 Share on other sites More sharing options...
premiso Posted December 2, 2009 Share Posted December 2, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969832 Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 Im thinking that $rs->Fields('Address') is an object, $rs->Fields('Address')->value being what needs to be tested or maybe try if(sizeof($rs->Fields('Address')) != 0)... Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969838 Share on other sites More sharing options...
SarahB12 Posted December 2, 2009 Author Share Posted December 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969841 Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 Ok ive never use OLE COM objects before. According to the spec "value" does contain the value in seems to be what should be used in the if statement. See if this gives you an error if(isset($rs->Fields('Address')->value))... Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969850 Share on other sites More sharing options...
SarahB12 Posted December 2, 2009 Author Share Posted December 2, 2009 @JustLikeIcarus if(isset($rs->Fields('Address')->value)) didn't work, but a variation of it did! if(trim($rs->Fields('Address')->value) !="") is the final product. Thanks guys! ~ SarahB ~ Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969861 Share on other sites More sharing options...
JustLikeIcarus Posted December 2, 2009 Share Posted December 2, 2009 Hahaha we were getting there. Quote Link to comment https://forums.phpfreaks.com/topic/183745-php-ms-access-line-break/#findComment-969863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.