0

I want to do this:

When user edits some text and clicks submit - for html to $_post the info into a FPDF file.

I'm stuck here:

<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->AddPage();
$pdf->Cell(60,10,'Powered by FPDF.',0,1,'C');

$pdf-> Output();
?>

How can I add a $_POST attribute? If I do, it gives an error.

Or if someone knows a way to connect to the database and display info from tables... that would be nice.

Example I found:

$query = "SELECT imageField FROM yyy WHERE ...";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$image = $row['imageField'];

$pdf->MemImage($image, 50, 30);

Obviously that is an image... how can it be done with text?

4

1 に答える 1

1

コードスニペットをコピーして貼り付けて機能させることを前提としています。投稿変数「name」が「MyName」に設定されているとすると、関数に渡す文字列と接触させることで印刷できます。

$pdf->Cell(40,10,'Hello World - '.$_POST[name]);

これにより、「HelloWorld-MyName」がPDFファイルに出力されます。

MYSQLデータベースに接続するには、次のステートメントが必要です。

mysql_connect('localhost','username','password');  //Replace 'username' and 'password' by your mysql username and password

mysql_select_db('db');  //Replace 'db' by the name of the database

次に、SQLクエリを実行して、上記のデータベースデータベースのテーブルテーブルからフィールドフィールド名を選択します。条件によって、選択する行が決まります。条件を1のままにすると、すべての行が選択されます。field2 ='somevalue'のような条件を使用して、field2の値がsomevalueである行のみを選択できます。

$query=mysql_query("SELECT *fieldname* FROM table WHERE condition "); 

結果を取得するには、関数mysql_fetch_assos()を使用します。

$row_array= mysql_fetch_assos($query);

mysql_fetch_assos()は、特定の行のフィールド値を含む連想配列を返し、リソースポインタを1つ移動します。

$field_value=$row_array['field2'];
于 2011-01-07T06:59:46.240 に答える