Hello community

I hope this PHP Question is also allowed in this forum

I would like to create a table which lists a sepc. query. Later I would like add a feature which allows exporting the result as a CSV. My current PHP Page does not work with my restrictive query. If I use "SELECT * FROM sugarcrm.accounts" it works fine... Does someone see the error and can help me?

<?php
/* Verbindung aufbauen, auswählen einer Datenbank */
$link = mysql_connect("crm", "root", "password")
or die("Keine Verbindung möglich: " . mysql_error());
echo "Verbindung zum Datenbankserver erfolgreich";
mysql_select_db("sugarcrm") or die("Auswahl der Datenbank fehlgeschlagen");

/* ausführen einer SQL Anfrage */
$query = "SELECT sugarcrm.accounts.name AS Firmenname, sugarcrm.accounts.billing_address_street AS Strasse,sugarcrm.accounts.billing_address_postalco de AS PLZ,sugarcrm.accounts.billing_address_city AS Stadt,sugarcrm.contacts.salutation AS Anrede,sugarcrm.contacts.first_name AS Vorname,sugarcrm.contacts.last_name AS Nachname FROM sugarcrm.accounts_contacts, sugarcrm.contacts, sugarcrm.accounts WHERE ( sugarcrm.accounts_contacts.contact_id = sugarcrm.contacts.id AND sugarcrm.accounts.id = sugarcrm.accounts_contacts.account_id) AND ( ( sugarcrm.accounts_contacts.deleted = 0 AND sugarcrm.accounts.deleted = 0 AND sugarcrm.contacts.deleted = 0 ) ) AND sugarcrm.accounts.sic_code = "Ja" ORDER BY Nachname ASC, Firmenname ASC";
$result = mysql_query($query) or die("Anfrage fehlgeschlagen: " . mysql_error());

/* Ausgabe der Ergebnisse in HTML */
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

/* Freigeben des Resultsets */
mysql_free_result($result);

/* schliessen der Verbinung */
mysql_close($link);
?>
Thanks,
Miguel