Steh grad aufm Schlauch mit MySQL Query

firstlord18

Erfahrenes Mitglied
Hallo,

habe folgenden Code:

PHP:
		//
		// get all rights, which are deleteable:
		$sql = 'SELECT 
					id, rightname, php_id 
				FROM 
					uM_rights
				WHERE
					id > 13';
		$res = $this->_query($sql);
	  
		while($row = mysql_fetch_assoc($res)) {
			
			$row['rightname'] = $this->prepareForInput( $row['rightname'] );
			
			
			$main[] = '	<tr>';
			$main[] = '		<td class="cols">';
			$main[] = '			<a class="infoBox" href="#">'.$row['rightname'];
			$main[] = '				<span>';	
			$main[] = '					<em class="head">davon betroffene User:</em>';
			
			//
			// select users, which are assigned with this right:
			$sql2 = 'SELECT 
						uM_users.username
					FROM
						uM_users,
						uM_users_rights
					WHERE	
						uM_users_rights.users_id = uM_users.id AND
						uM_users_rights.rights_id = "'.$this->_secure( $row['id'] ).'" AND
						uM_users.id > 1';
						
			$res2 = $this->_query($sql2);	
			
			while($row2 = mysql_fetch_assoc($res2) ) {
				$main[] = '				<abbr class="recht"> - '.$row2['username'].'</abbr><br />';
			}	

			$main[] = '					<br /><em class="head">davon betroffene Gruppen:</em>';
			
			//
			// select groups, which are assigned with this right:
			$sql3 = 'SELECT 
						uM_groups.groupname
					FROM
						uM_groups,
						uM_groups_rights
					WHERE	
						uM_groups_rights.groups_id = uM_groups.id AND
						uM_groups_rights.rights_id = "'.$this->_secure( $row['id'] ).'" AND
						uM_groups.id > 1';
						
			$res3 = $this->_query($sql3);	
			
			while($row3 = mysql_fetch_assoc($res3) ) {
				$main[] = '				<abbr class="recht"> - '.$row3['groupname'].'</abbr><br />';
			}	
			
			$main[] = '		</td>';
			$main[] = '	</tr>';			
		}

habe nur das wichtigste gepostet. Nun frage ich mich, ob man das auch alles in einem Query lösen kann, da sonst für jedes Recht nochmal 2 Querys ausgeführt werden. Also wenn ich dann irgendwann mal so 10 Rechte habe, dann sinds gleich 20 Querys ...

vielen Dank im voraus!
 
Zuletzt bearbeitet:
Zurück