josephman1988 Posted September 8, 2011 Report Share Posted September 8, 2011 Hi guys, I've been working with PHP for a while, and now moving onto OOP, which is proving to be annoyingly hard! I know it might be 're-inventing the wheel', but I'm trying to understand how it all slots together and works, so please hold back a little ;]. The following function is supposed to get the arguments chucked through and run a query, which works fine, i also count the rows in it. However, I want to print the results of the loop as you would normally but OOP in mind. I can loop it and style it easily within the function, but because I may want this data again and again (in different formats across the site), i want to be able to print it out by calling in the class/function. How would I do this? Any tips? What am I doig wrong and/or misunderstanding? Code is as follows: public $numOfQuery; public function select($table, $rows = "*", $where = null, $order = null) { $query = "SELECT " . $rows . " FROM " . $table . ""; if ($where != null) {$query .= " WHERE " . $where . "";} if ($order != null) {$query .= " ORDER BY " . $order . "";} $getQuery = @mysql_query($query); $this->numOfQuery = mysql_num_rows($getQuery); } Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 9, 2011 Report Share Posted September 9, 2011 Can't you just loop through the results, adding the results to a string, and then return the results at the end of the function? Quote Link to comment Share on other sites More sharing options...
josephman1988 Posted September 10, 2011 Author Report Share Posted September 10, 2011 Yer but I don't want to style them in the function itsel'f, is there a way to somehow get the results and pprint them outside the function? For example, I want to print a list of games for a navigation, then i want to print a list for whatever reason in a differnt style .. defining the style in the function will make the data look exactly the same won't it. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 10, 2011 Report Share Posted September 10, 2011 Could you just return $getQuery, then loop through the results outside of the function? Or have the function return a 2D array of the results (meaning you do two loops, one inside your function to generate the 2D array, and one outside your function to display the results.) Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.