Jump to content

Looping results in OOP


josephman1988

Recommended Posts

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);

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...