Jump to content

Mysqli and OOP PHP Problems


Mod-Jay

Recommended Posts

The following code is supposed to submit everything in the database on a table, Currently its doing the first row in the database. Not sure whats wrong..

 

 

	function getNews(){
	$query = $this->con->query("SELECT * FROM `". $this->prefix ."news`");
	while ($result = $query->fetch_assoc()) {
		if($result['serveradded'] == 1){
			$queryy = $this->con->query("SELECT * FROM `". $this->prefix ."news` WHERE serveradded=1");
			while ($resultt = $queryy->fetch_assoc()) {
				return "<tr><td>The Advertisement ". ucfirst($resultt['name']) ." was created</td><td>". $resultt['date'] ."</td></tr>";
			}
		} elseif($result['servupdate'] == 1){
			$queryyy = $this->con->query("SELECT * FROM `". $this->prefix ."news` WHERE servupdate=1");
			while ($resulttt = $queryyy->fetch_assoc()) {
				return "<tr><td>".  $result['type'] ." ". ucfirst($resulttt['name']) ." was Updated by ". ucfirst($resulttt['updatedby']) ." </td><td>". $resulttt['date'] ." </td></tr>";
			}
		} elseif($result['newuser'] == 1){
			$queryyyy = $this->con->query("SELECT * FROM `". $this->prefix ."news` WHERE newuser=1");
			while ($resultttt = $queryyyy->fetch_assoc()) {
				return "<tr><td>Account Created: ". ucfirst($resultttt['name']) ." was created</td><td>". $resultttt['date'] ."</td></tr>";
			}

		}

	}

}

Link to comment
Share on other sites

Perhaps if you post an example of the data you have and the result you want, someone could help. In looking at that code, I doubt anyone here can tell what it is you are trying to accomplish. You would never select all your data, then as you loop through each row, reselect some of the same data again.

 

If the three columns - serveradded, servupdate, and newuser are actually types/categories, why don't you have one column named `type` or `category` that holds either 'serveradded', 'servupdate', or 'newuser' directly as strings or as values/enums to indicate the type for that row?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.