PdVortex Posted November 19, 2009 Author Share Posted November 19, 2009 Thats wicked and perfectly explained thanks very much appreciate it a lot. One last question for you, is this part necessary? $cols = implode( ', ', array( FORUM_TOPIC, TID ) ); could i not just add the constants directly into the sql line or just the table colum names i need? something like this $sql = " SELECT id, topic FROM forum_topic WHERE forum_topic.user_id='{$this->userId}' ORDER BY datetime DESC LIMIT 5 "; Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/182085-php-oop-help/page/2/#findComment-961520 Share on other sites More sharing options...
roopurt18 Posted November 19, 2009 Share Posted November 19, 2009 Both are equivalent ways of specifying the columns. FYI, when I first started PHP I used constants for my columns and table names. IMO it's more effort than it's worth and I haven't done that in a loooooooooooong time. I do it like this: $sql = " SELECT id, topic FROM forum_topic WHERE forum_topic.user_id='{$this->userId}' ORDER BY datetime DESC LIMIT 5 "; I typically write my queries in all lower case as well: select id, topic from forum_topic ... And you should properly enclose your table and column names in the delimiter expected by the database engine: select `id`, `topic` from `forum_topic` ... Quote Link to comment https://forums.phpfreaks.com/topic/182085-php-oop-help/page/2/#findComment-961525 Share on other sites More sharing options...
keldorn Posted November 19, 2009 Share Posted November 19, 2009 Where are you getting $this->userId ? That looks to be undefined. (by your code).. If you want to do this, you have to convert it to an asscotive array, the loop over it in the html. So function forumTopics() { $sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime ASC LIMIT 5"; $tmp = mysql_query($sql); while ($line = mysql_fetch_assoc($tmp)){ $result[] = $line; } // Check if its an array (meaning there is a result) if(is_array($result)){ return $result; } else { return false; } $Topics = $user->forumTopics($user); // if returned false, then this will trigger. if(!$topics){ // nothing found error } // Then loop it Quote Link to comment https://forums.phpfreaks.com/topic/182085-php-oop-help/page/2/#findComment-961535 Share on other sites More sharing options...
roopurt18 Posted November 20, 2009 Share Posted November 20, 2009 He could accomplish returning false or an array of results with one change: return count( $FTopics ) === 0 ? false : $FTopics; Quote Link to comment https://forums.phpfreaks.com/topic/182085-php-oop-help/page/2/#findComment-961538 Share on other sites More sharing options...
keldorn Posted November 20, 2009 Share Posted November 20, 2009 He could accomplish returning false or an array of results with one change: return count( $FTopics ) === 0 ? false : $FTopics; ternary operation ftw. Quote Link to comment https://forums.phpfreaks.com/topic/182085-php-oop-help/page/2/#findComment-961540 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.