2017-11-30 3 views
-1

私はPHPでいくつかの問題を抱えています。私はMySQLデータベースからいくつかのデータをフェッチするPHPで動的XMLファイルを作成します。私はあなたの問題は、あなたが文字列にあなたの変数を追加しようとする前に、あなたの見積もりを終了していないことかもしれないと思うphpとmysqliを使って動的なxmlを作成する際の問題

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /opt/lampp/htdocs/buuuh.php on line 13 
+0

はあなたがすべてのエラーメッセージを投稿してくださいすることができ、このコード行をommenting、または出力あなたは –

+0

は必ず私がポスト:) –

+0

「anzahl」実際のラインまでよりerrosがあると行にエラーイスト編集してきています18とその後、私はこのエラーを取得します - > 2行目の1列目のエラー:ドキュメントの末尾の余分な内容 –

答えて

0

<?php 
header("Content-type: text/xml"); 
echo '<?xml version="1.0" encoding="UTF-8"?>'; 

$sql = "SELECT bestellpositionen.id_bestellung, bestellpositionen.id, bestellpositionen.anzahl, produkte.preis * bestellpositionen.anzahl AS preisGesamt, bestellpositionen.id_produkt, produkte.name, produkte.beschreibung, produkte.preis AS preisEinzeln FROM bestellpositionen LEFT OUTER JOIN produkte ON (produkte.id = bestellpositionen.id_produkt) ORDER BY bestellpositionen.id_bestellung"; 
$result = $db->query($sql); 
?> 
<statistik> 
<?php 
foreach ($result as $row) { 
    echo '<bestellung id="' . $row['id_bestellung'] . '">'; 
    echo '<bestellposition id="' . $row['id'] . '">\n'; 
    echo " <anzahl>. $row['anzahl'] .</anzahl>\n\n"; 
    echo " <preis>. $row['preisGesamt'] .</preis>\n\n"; 
    echo '<produkt id="' . $row['id_produkt'] . '">\n'; 
    echo " <name>. $row['name'] .</name>\n\n"; 
    echo " <beschreibung>. $row['beschreibung'] . 
</beschreibung>\n\n"; 
    echo " <preis>. $row['preis'] .</preis>\n\n"; 
    echo "</produkt>"; 
    echo "</bestellposition>"; 
    echo "</bestellung>"; 
} 

?> 
</statistik> 

私は次のエラーを取得しています:私のコードを以下に示します。この方法を試してください。

は、ライン13上のたとえばあなたが

echo " <anzahl>. $row['anzahl'] .</anzahl>\n\n"; 

を持っていたところ、それはリットル必要としてOOKこのような:

echo " <anzahl>". $row['anzahl'] ."</anzahl>\n\n";  

あなたの全体のブロックを使用すると、上記のコメントで述べたように

error on line 2 at column 1: Extra content at the end of the document 

あなたの2番目のエラーについては、この

<?php 
header("Content-type: text/xml"); 
echo '<?xml version="1.0" encoding="UTF-8"?>'; 

$sql = "SELECT bestellpositionen.id_bestellung, bestellpositionen.id, bestellpositionen.anzahl, produkte.preis * bestellpositionen.anzahl AS preisGesamt, bestellpositionen.id_produkt, produkte.name, produkte.beschreibung, produkte.preis AS preisEinzeln FROM bestellpositionen LEFT OUTER JOIN produkte ON (produkte.id = bestellpositionen.id_produkt) ORDER BY bestellpositionen.id_bestellung"; 
$result = $db->query($sql); 

echo "<statistik>"; 

foreach ($result as $row) { 
    echo '<bestellung id="' . $row['id_bestellung'] . '">'; 
    echo '<bestellposition id="' . $row['id'] . '">\n'; 
    echo " <anzahl>". $row['anzahl'] ."</anzahl>\n\n"; 
    echo " <preis>". $row['preisGesamt'] ."</preis>\n\n"; 
    echo '<produkt id="' . $row['id_produkt'] . '">\n'; 
    echo " <name>". $row['name'] ."</name>\n\n"; 
    echo " <beschreibung>". $row['beschreibung'] ."</beschreibung>\n\n"; 
    echo " <preis>". $row['preis'] ."</preis>\n\n"; 
    echo "</produkt>"; 
    echo "</bestellposition>"; 
    echo "</bestellung>"; 
} 
echo "</statistik>"; 

?> 

のようになります。あなたの質問では、この問題をcで解決することができました

header("Content-type: text/xml"); 
+0

ああありがとうございます:)ありがとうございます - しかし今はまだこの奇妙なエラーを取得しています - > 1行の2行目のエラー:ドキュメントの最後の余分な内容 - 2日間、たくさんの機能を試しました –

+0

これは '?>'のファイルの最後を 'echo" "に変更したために起こりました。 ?> 'あなたは同じエラーがある場所がありますか? '><?php'から 'echo" ";' –

関連する問題