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.

Einzelne Felder von mySQL in FPDF ausgeben

Empfohlene Antworten

Veröffentlicht

Morsche! :)

ma wieder was fröhliches.

Ich möchte gerne PDFs von PHP via FPDF generieren lassen. Das funktioniert im Prinzip auch schon mal, zumindest bei "statischem" Text.

Jetzt möchte ich aber immer einzelnen Felder aus einer mySQL-DB in das PDF reinschreiben, und ich kriegs absolut nich gebacken:



include('db_open.php');

$hidden = "test124";

$sql= "SELECT kontrollsystemauf FROM takontrolle WHERE tanr='".$hidden."'";
$res= mysql_query($sql, $db);
[/php]

Das ganze soll dann hier ausgegeben werden:

[php]
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=100;$i++)
$pdf->Cell(0,10,'mySQL Test'.$res,0,1);
$pdf->Output();

Hat jemand ne Idee, warum das nich funktioniert? Fehlermeldung is:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\www\thomastest\test.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at D:\www\thomastest\test.php:8) in D:\www\thomastest\fpdf.php on line 1022

FPDF error: Some data has already been output to browser, can't send PDF file

Danke schonmal :)

Gib dir mal den SQL aus den du da zusammenbaust und setzt Ihn z.b. mit PHPMyAdmin ab.

Laut fehlermeldung müsste dort ein Fehler vorliegen.

Der 2. Fehler ist nur ein Folgefehler.

Gruß,

Markus

im phpmyadmin mit dem richtigen Wert statt der $hidden gehts.

Schreib ich das fürs PHP um, bekomme ich:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\www\thomastest\test.php on line 8

Egal, ob ich den wert von tanr nun in einfachen Anführungstricherln mach, ohne, mit doppelten, weißichnich :(

einfach mal


include('db_open.php');

$hidden = "test124";

$sql= "SELECT kontrollsystemauf FROM takontrolle WHERE tanr='".$hidden."'";
$res= mysql_query($sql, $db);
echo $sql;
[/PHP]

machen, und was ausgegeben wird in phpmyadmin testen...

Auweia, saublöd...

natürlich geht es nicht, wenn man ne Funktion db_open() baut, die aber dann gar nicht aufruft...

Nun krieg ich keine Fehlermeldungen mehr, aber im $res kommt im PDF gar nix, bzw. bei nem Echo ein Resource id#4 (oder 5), keine Ahnung woher...

siehe beispiel eines datenbankzugriffs auf MySQL aus dem Manual:


<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}

mysql_free_result($result);
?>
[/PHP]

http://de2.php.net/manual/en/function.mysql-fetch-array.php

http://de2.php.net/manual/en/function.mysql-fetch-assoc.php

http://de2.php.net/manual/en/function.mysql-fetch-row.php

Jo, bin heute nich gut drauf glaub ich. Ohne mysql_result() nen Result wollen...naja ;)

Danke für deine Hilfe Kills, mittlerweile fließt in das PDF nun auch DB-Inhalt ein :)

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.