---
title: "Probleme mit JOIN"
url: "https://www.typo3.net/d/104999-probleme-mit-join"
source: "typo3.net"
tags: ["Extensions","Entwicklung","Frage"]
created: "2011-04-19"
last_reply: "2011-04-19"
replies: 3
solved: false
page: 1
pages: 1
lang: "de"
---

# Probleme mit JOIN

Extensions › Entwicklung · 3 Antworten · gestartet 2011-04-19

## Eröffnungsbeitrag

**lil-trick** · 2011-04-19 · [Beitrag #1](https://www.typo3.net/d/104999-probleme-mit-join/1)

Hallo,

hab ein Problem mit INNER JOIN - er gibt mir nichts aus :(

```php
//Datensätze holen
$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
'a.uid, a.title',
'tx_item_produkt a 
INNER JOIN tx_item_produkt_category_mm ac ON (ac.uid_local=a.uid) 
INNER JOIN tx_item_Cat c ON (c.uid=ac.uid_foreign)',
'hidden=0 and deleted=0',
$groupBy='',
$orderBy= '',
$limit='');

while($row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$markerArray['###UID###']= $row['uid'];
$markerArray['###TITLE###']= $row['title'];
$liste .= $this->cObj->substituteMarkerArrayCached($singlerow,$markerArray);
}
```

hab das Ganze aber in einem PHP Script nachgebaut und da funktionierts

```php
$sql = "SELECT a.uid, a.title
FROM tx_item_produkt a
INNER JOIN tx_item_produkt_category_mm ac ON ( ac.uid_local = a.uid )
INNER JOIN tx_item_Cat c ON ( c.uid = ac.uid_foreign )";

$abfrage = mysqli_query($verbindung, $sql);

while($articel = mysqli_fetch_assoc($abfrage)){
echo "<tr>";
echo "<td>$articel[uid] ja</td>";
echo "<td>$articel[title] </td>";
echo "<td>$articel[category]</td>";
echo "</tr>";
}
echo "</table>";
mysqli_free_result();
```

kann mir einer sagen warum :D

danke

## Antworten

### [#2](https://www.typo3.net/d/104999-probleme-mit-join/2) · Julian.​Hofmann · 2011-04-19

Hallo.
Glaube, Du hast in Deinem nachbau den Teil vergessen, der das leere Result - bzw. genauer, den Fehler - verursacht ausgelassen.

Du übergibst an die  exec_SELECTquery() die WHERE-Clause 'hidden=0 and deleted=0', hast aber innerhalb Deines FROM drei Tabellen. Welche soll hier angesprochen werden?

```php
//Datensätze holen
$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
'a.uid, a.title',
'tx_item_produkt a 
INNER JOIN tx_item_produkt_category_mm ac ON (ac.uid_local=a.uid) 
INNER JOIN tx_item_Cat c ON (c.uid=ac.uid_foreign)',
'tx_item_produkt.hidden=0 AND tx_item_produkt.deleted=0 AND tx_item_Cat.hidden=0 AND tx_item_Cat.deleted=0' ,
$groupBy='',
$orderBy= '',
$limit='');

if ($res) { 
  while($row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
    $markerArray['###UID###']= $row['uid'];
    $markerArray['###TITLE###']= $row['title'];
    $liste .= $this->cObj->substituteMarkerArrayCached($singlerow,$markerArray);
  }
  $GLOBALS['TYPO3_DB']->sql_free_result($res);
} else {
  echo "Da ging was schief...";
}
```

Viele Grüße
Julian

### [#3](https://www.typo3.net/d/104999-probleme-mit-join/3) · lil-trick · 2011-04-19

da wäre ich nicht drauf gekommen danke Julian.

Ich möchte jetzt aber zusätzlich noch über eine Variable $auswahl = '1,2,3,4 usw.' festelegen können welche Kategorien angezeigt werden - in meinem test PHP funktioniert das Ganze in typo wieder nicht :(

```php
//Datensätze holen

$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
'a.uid AS uid_local, a.title, c.cat_cat AS category',
'tx_item_produkt a 
INNER JOIN tx_item_produkt_category_mm ac ON (ac.uid_local=a.uid) 
INNER JOIN tx_item_Cat c ON (c.uid=ac.uid_foreign)',
'a.hidden=0 and a.deleted=0 and c.hidden=0 and c.deleted=0',
$groupBy='',
$orderBy= '',
$limit='');

if ($auswahl == '') {
 }else {
$res .='WHERE ac.uid_foreign IN ('.$auswahl.') GROUP BY a.uid';
}
```

### [#4](https://www.typo3.net/d/104999-probleme-mit-join/4) · Julian.​Hofmann · 2011-04-19

In $res hast Du einen MySQL result pointer, keinen String mehr. D.h. hier ist es zu spät, noch an der Query was drehen zu wollen.

Schau Dir am besten mal die Doku zu [exec_SELECTquery()](http://api.typo3.org/typo3v4/current/html/classt3lib___d_b.html#a3e108e17834da69d638f3d9301f06628) - evtl. auch direkt im PHP-code. Damit wird IMHO deutlicher, wo/wie man an den Queries drehen kann.

---

Quelle: „Probleme mit JOIN“, typo3.net, https://www.typo3.net/d/104999-probleme-mit-join
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
