rockinaway Posted January 13, 2012 Share Posted January 13, 2012 How can I check if a returned mysql value is equal to '' i.e. nothing? I keep getting an error where the page won't load because the returned value is '' so i need to check for it Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/ Share on other sites More sharing options...
Muddy_Funster Posted January 14, 2012 Share Posted January 14, 2012 if (trim($row['fieldname']) == '' || empty($row['fieldname']){ //do something } Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307437 Share on other sites More sharing options...
rockinaway Posted January 14, 2012 Author Share Posted January 14, 2012 I tried empty, but I got a strange fatal error 'Can't use method return value in write context' Will the trim part help with this? I should add that I am using mysql_result Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307440 Share on other sites More sharing options...
wolfcry Posted January 14, 2012 Share Posted January 14, 2012 Have you tried comparing it against NULL? if ($row['fieldname'] == NULL){ do something. } Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307442 Share on other sites More sharing options...
trq Posted January 14, 2012 Share Posted January 14, 2012 I tried empty, but I got a strange fatal error 'Can't use method return value in write context' Why not try posting that problematic code then? Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307493 Share on other sites More sharing options...
rockinaway Posted January 14, 2012 Author Share Posted January 14, 2012 if ($this->db->num_rows($mini_thought_query) == 1) $this->member['mini_thought'] = $this->db->result($mini_thought_query); This is the line. I have some classes but they are just the basic mysql_result etc, just in classes. I want to check if the value returned in the result is an empty value or whether there is actually some text there. Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307513 Share on other sites More sharing options...
trq Posted January 14, 2012 Share Posted January 14, 2012 That really isn't enough code to be helpful. Why don't you just try and work it out for yourself? Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307524 Share on other sites More sharing options...
rockinaway Posted January 14, 2012 Author Share Posted January 14, 2012 I've been trying, that's the only line with the problem. I'll keep at it.. thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307536 Share on other sites More sharing options...
Muddy_Funster Posted January 14, 2012 Share Posted January 14, 2012 thats the line throwing the error, the problem can be realted to any line of code that includes variable contnent used by that line. It's always better to post too much rather than too little code. let's see the full page. Quote Link to comment https://forums.phpfreaks.com/topic/254984-mysql-result/#findComment-1307553 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.