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.

Empfohlene Antworten

Veröffentlicht

Hallo zusammen, nun meld ich mich auch mal wieder.

Habe ein Problem mit meiner Abfrage und komme nicht weiter.

Hab schon im INternet gesucht aber nichts gefunden.

Ich hab zwei Tabellen, eine mit Infos zu Firmen und eine mit den Ansprechpartnern.

Jetzt möchte ich das zu jeder Firma jeder Ansprechpartner angezeigt wird,

und die Firma aber nur einmal, und nicht für jeden Ansprechpartner.

Meine Tabelle zur Ausgabe sieht folgendermaßen aus:


Firmenname | Ansprechpartner | Telefon | Fax | Diverses1 | Diverses2
[/PHP]

Tabellen in der mySQL - DB:

[PHP]
Tabelle1:
- id | Firmenname | Diverses1 | Diverses2

Tabelle2:
- id | tabelle1_id | Ansprechpartner | Telefon | Fax

Hoffe mir kann jemand helfen, wie ich alle Firmen angezeigt bekomme

(nur 1 mal) und alle Ansprechpartner jeweils zu den Firmen.

Gruß

TripleD

select firmenname, ansprechpartner from tabelle1, tabelle2 where tabelle1.id=tabelle2.tabelle1_id;

Es ist logisch, dass Du folgende Ergebnisse bekommst.

Firma, Ansprechpartner

a, herr x

a, frau b

c, herr k

d, frau z

Was soll SQL denn machen. Er bekommt aus der zweiten Tabelle zwei Datensätze und aus der ersten nur einen passenden. Also fügt er den einen Satz nochmal vorne dran. Du mußt dann bei der Ausgabe eine kleine Abfrage machen.

Frank

wieso nicht das ganze in 2 zügen machen?

du verwendest PHP?

ich geh ma davon aus...


$sql = "select firma from tabelle1";
$res = mysql_query( $sql);
echo "<table>";
while( $firm = mysql_fetch_assoc( $res)) {
echo "<tr>";
$sql = "select person from tabelle2 where firmaId = ". $firm['id'];
$res2 = mysql_query( $sql);
echo "<td>". $firm['name'] ."</td>";
echo "<td>";
while( $person = mysql_fetch_assoc( $res2)) {
echo $person['name'] . "<br/>";
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
[/PHP]

Hallo,

erst mal danke für eure Hilfe.

Aber irgendwie passt da was noch nicht, und ich komm nicht drauf.

Hier mal der Quellcode:


<html>
<head>
<title>
Telefonliste Lieferant
</title>
<link rel="stylesheet" type="text/css" href="../../config/table.css">

<script language="JavaScript">
<!--
var nw;
function detail(url)
{
nw=window.open(url,'Drucken','height=500,width=800');
if (window.focus)
{
nw.focus()
}
}
//-->
</script>
</head>
<body>
<table>
<colgroup>
<col width="140"> <!-- Lieferant -->
<col width="120"> <!-- Ansprechpartner -->
<col width="100"> <!-- Telefon -->
<col width="100"> <!-- Fax -->
<col width="50"> <!-- Fracht -->
<col width="150"> <!-- Zahlungsbedingungen -->
</colgroup>
<tr>
<td>
<font size="3"><b>Lieferant</b></font>
</td>
<td>
<font size="3"><b>Ansprechpartner</b></font>
</td>
<td>
<font size="3"><b>Telefon</b></font>
</td>
<td>
<font size="3"><b>Fax</b></font>
</td>
<td>
<font size="3"><b>Fracht</b></font>
</td>
<td>
<font size="3"><b>Zahlungsbedingungen</b></font>
</td>
<td>
LFR
</td>
<td>
LFR
</td>
<td>
AP
</td>
<td>
AP
</td>
<td>
<a href="javascript:detail('print.php');"><img src="../../images/print.png" border="0" width="15" height="15" alt="Drucken"></a>
</td>
<td>
<a href="add.php"><img src="../../images/add.png" border="0" width="15" height="15" alt="Hinzufügen"></a>
</td>
</tr>
<?php
include('../connect.php');

$sql_lfr = "SELECT * FROM ".$T_LFR_LFR
OR die('Fehler bei Abfrage: '.mysql_error());

$result_lfr = mysql_query($sql_lfr)
OR die('Fehler bei Ausfürung: '.mysql_error());

while($lfr = mysql_fetch_assoc($result_lfr))
{
?>
<tr>
<td valign="top">
<?php
echo '<font size="2"><b>'.$lfr['firma'].'</b></font><br>';
echo '<font size="2"><b>Kunden-Nr.: '.$lfr['kdnr'].'</b></font><br>';
echo '<font size="2"><b>'.$lfr['oz'].'</b></font>';
?>
</td>
<?php
$sql_ap = "SELECT * FROM ".$T_LFR_AP
OR die('Fehler bei Abfrage: '.mysql_error());

$result_ap = mysql_query($sql_ap)
OR die('Fehler bei Ausfürung: '.mysql_error());

while($ap = mysql_fetch_assoc($result_ap))
{
?>
<td valign="top">
<?php
echo '<font size="2">'.$ap['ap'].'</font>';
?>
</td>
<td valign="top">
<?php
echo '<font size="2">'.$ap['tel'].'</font>';
?>
</td>
<td valign="top">
<?php
echo '<font size="2">'.$ap['fax'].'</font>';
?>
</td>
<?php
}
?>
<td valign="top">
<?php
echo '<font size="2">'.$lfr['fracht'].'</font>';
?>
</td>
<td valign="top">
<?php
echo '<font size="2">'.$lfr['zb_div'].'</font>';
?>
</td>
<td>
<?php
echo '<a href="edit.php?id='.$lfr[id].'"><img src="../../images/update.png" border="0" alt="Bearbeiten"></a>';
?>
</td>
<td>
<?php
echo '<a href="del_go.php?id='.$lfr[id].'"><img src="../../images/delete.png" border="0" alt="Löschen"></a>';
?>
</td>
<td>
<?php
echo '<a href="edit.php?id='.$ap[id].'"><img src="../../images/update.png" border="0" alt="Bearbeiten"></a>';
?>
</td>
<td>
<?php
echo '<a href="del_go.php?id='.$ap[id].'"><img src="../../images/delete.png" border="0" alt="Löschen"></a>';
?>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
[/PHP]

Und hier die dazugehörige ausgabe:

>

>

bild1.png

$sql_lfr = "SELECT * FROM ".$T_LFR_LFR

OR die('Fehler bei Abfrage: '.mysql_error());

Hier kann niemals ein mysql_error auftreten, da du ne ganz normale String zuweisung machst...

Gruß,

Markus

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.