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
https://forums.phpfreaks.com/topic/245999-mysqli-and-oop-php-problems/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.