Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Probleme mit MySQL-Abfrage aus mehreren Tabellen gleichzeitig

Empfohlene Antworten

Veröffentlicht

Moin Ihr!

Ich hab da mal ein Problem mit einer MySQL-Abfrage. Die Sache ist folgende: Ich baue grad ein Forum bestehend aus drei Tabellen. Eine enthält die Foren selbst (forum_master), eine andere Titel und Datum der Threads (forum_threads) und die letzte den eigentlichen Inhalt der Threads (forum_content).

Nun möchte ich die Thread-Titel nach Datum des letzten Beitrags geordnet auflisten. Dazu benötige ich sämtliche Spalten aus der forum_threads-Tabelle und eben das Datum aus der forum_content-Tabelle.

Jede der Tabellen enthält 3 Einträge, und normalerweise sollten da auch nur drei Einträge in der Liste erscheinen, aber mit meiner Abfrage sind's seltsamerweise 18 Einträge, wobei die 3 besagten jeweils 6x wiederholt werden...

Hab keine Ahnung, woran's liegt, aber ich hab bisher leider auch noch keine Erfahrungen mit Abfragen aus mehreren Tabellen...

Naja, hier mal der Quellcode:

 <?php

 if($HTTP_SESSION_VARS)

   $datum1 = $HTTP_SESSION_VARS["lastlogin"];

 else

   $datum1 = date ("Y-m-d H:i:s");


 $abfrage = "SELECT forum_threads.* FROM forum_threads WHERE forum_threads.forumID=$id1 ORDER BY forum_content.datum2 DESC";

 $erg = mysql_db_query($dbname,$abfrage,$conn);

 while(list($id,$Name,$author,$datum,$datum2,$typ,$forumID,$symbol) = mysql_fetch_row($erg))

 {  

   $replycount = "SELECT COUNT(*) AS anzahl FROM forum_content WHERE threadID = $id";

   $replies = mysql_db_query($dbname,$replycount,$conn);

   $count = mysql_fetch_array($replies);

   $count[anzahl] = $count[anzahl] - 1;


   $datumcheck = "SELECT datum,datum2 FROM forum_content WHERE threadID = $id ORDER BY datum2 DESC";

   $lastdate1 = mysql_db_query($dbname,$datumcheck,$conn);

   list($lastdate,$lastdate2) = mysql_fetch_row($lastdate1);


   echo "<tr>\n<td class='forum'><b><a href='c_forum_thread.php?thread=$id&forum=$id1'>$Name</a></b></td>

   <td class='forum'><p>$author</p></td>

   <td class='forum'><p>$count[anzahl]</p></td>";


   if($lastdate2 >= $datum1)

     echo "<td class='forum'><p>$lastdate <b>neu!!</b></p></td>\n</tr>\n";

   else

     echo "<td class='forum'><p>$lastdate</p></td>\n</tr>\n";

 }

?>

 

Ach ja, das Forum ist als Betaversion bereits hier zu finden: http://forum.freeqnet.de

<FONT COLOR="#a62a2a" SIZE="1">[ 20. September 2001 12:58: Beitrag 1 mal editiert, zuletzt von beetFreeQ ]</font>

Hmmm, also versuchs doch mal so !

<*SELECT "SELECT * FROM Suppliers JOIN Products ON (Suppliers.SupplierID = Products.SupplierID)"*>

Hier sind Suppliers und Products 2 Tabellen. Es wird nach der SupplierID geordnet (sprich die 2. tabelle ordnet die Reihen nach der SupplierID die in beiden Tabellen vorhanden ist). Ausgelesen werden hier natürlich beide tabellen komplett !

Dannach gehst du mit dem Select ganz normal weiter (MAP, GET usw.).

Hoffe das hilft dir !

Bei mir hats bis auf die Formatierungen der Ergebnistabelle hingehaun !

Gruß

A.f.h.

  • Autor

thx, aber das wollte bei meinen Tabellen auch nicht so...

Hab jetzt aber ne andere Lösung: Ich habe jetzt das Datum mit in der forum_thread-Tabelle und aktualisiere es bei jeder neuen Antwort einfach mit! Dadurch brauche ich für die Auflistung nur eine Tabelle abzufragen...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.