我必须将数据库中的记录下载到word文件中。但是我无法这样做,因为每当我在桌子周围添加循环时它都会给我错误。
当我获取单个记录时,我的代码工作正常。 有人可以为我提供获取多条记录的方法。
这是我的代码:
<?php
include('dbcon.php');
if($_GET['id']!='')
$id=$_GET['id'];
$party_name=mysql_query("select * FROM tb_party Where party_id='".$id."' ");
$party_name_row=mysql_fetch_array($party_name);
$sample_text1 = $party_name_row['party_name'];
$party_details="select * from tb_party_rate_entry
where party_id='$id'";
$query_details=mysql_query($party_details);
$row_details=mysql_fetch_array($query_details);
$word_xmlns = "xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:w='urn:schemas-microsoft-com:office:word'
xmlns='http://www.w3.org/TR/REC-html40′";
$word_xml_settings = "<xml><w:WordDocument>
<w:View>Print</w:View><w:Zoom>100</w:Zoom></w:WordDocument></xml>";
$word_landscape_style =
"@page {size:8.5in 11.0in; margin:0.5in 0.31in 0.42in 0.25in;
} div.Section1{page:Section1;}";
$word_landscape_headinh="{font-size:15px; }";
$word_landscape_div_imf='
<img src="http://silverevents.net/user_image/' .$sample_text1 . '"
height="150" width="150"/>';
$word_landscape_div_start = "<div class='Section1′>";
$word_landscape_div_end = "</div>";
$content = '<html '.$word_xmlns.'>
<head>
<title>Party Rate Report</title>'
.$word_xml_settings.'<style type="text/css">
'.$word_landscape_style.' table,td
{border:1px solid #FFFFFF; width:200px; color:#CCC;} </style>
</head>
<body>'.$word_landscape_div_start .
'<table style="width:500px; color:#000000;
margin:0 0 50px 100px; font-family: Arial Black, Gadget,
sans-serif; font-size:24px;"><tr><td> Party Rate Report </td>
</tr></table></br>
<table style="width:700px;font-size:15px;font-family:
Arial Black, Gadget, sans-serif;">
<tr>
<td width="180">
Party Name : '. $party_name_row['party_name'] . '
</td>
<td width="250">
Address : '. $party_name_row['party_address'] . '
</td>
<td width="150">
Phone : '. $party_name_row['phone_no']. '
</td>
</tr>
</table><br/>
<table style="width:700px; color:#00000; margin:22px 0 0 0px;
font- family:Helvetica, sans-serif, Verdana;
font-size:15px; border1px solid #666;">
<tr>
<td style=" border:1px solid #666; width:300px;"> Zone</td>
<td style=" border:1px solid #666; width:300px;">
Delivery Mode
</td>
<td style=" border:1px solid #666; width:300px;"> Doc Type </td>
<td style=" border:1px solid #666; width:300px;"> Weight slot </td>
<td style=" border:1px solid #666; width:300px;"> Weight Unit </td>
<td style=" border:1px solid #666; width:300px;"> Flat </td>
<td style=" border:1px solid #666; width:300px;"> Price </td>
</tr>
<tr>
<td style=" border:1px solid #666; width:300px;">' .
$row_details['zone_id']. '</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['delivery_mode_id'].'
</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['doc_type_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_slot_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_measure_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['flat'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['price' ] . '</td>
</tr>
</table></br>' . $word_xml_settings. $word_landscape_div_end.'
</body>
</html>';
@header('Content-Type: application/msword');
@header('Content-Length: '.strlen($content));
@header('Content-disposition: inline; filename="Party Rate Report.doc"');
echo $content;
?>
这是我的数据库:
答案 0 :(得分:1)
做这样的事情:
while ($row_details=mysql_fetch_array($query_details)) {
//do row specific code
}
答案 1 :(得分:1)
快速重新格式化,添加一个循环(并假设id是一个整数): -
<?php
include('dbcon.php');
if($_GET['id']!='')
{
$id=intval($_GET['id']);
$party_name=mysql_query("select * FROM tb_party Where party_id=$id ");
if ($party_name_row=mysql_fetch_array($party_name))
{
$sample_text1 = $party_name_row['party_name'];
}
$word_xmlns = "xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:w='urn:schemas-microsoft-com:office:word'
xmlns='http://www.w3.org/TR/REC-html40'";
$word_xml_settings = "<xml><w:WordDocument>
<w:View>Print</w:View><w:Zoom>100</w:Zoom></w:WordDocument></xml>";
$word_landscape_style =
"@page {size:8.5in 11.0in; margin:0.5in 0.31in 0.42in 0.25in;
} div.Section1{page:Section1;}";
$word_landscape_headinh="{font-size:15px; }";
$word_landscape_div_imf='
<img src="http://silverevents.net/user_image/' .$sample_text1 . '"
height="150" width="150"/>';
$word_landscape_div_start = "<div class='Section1'> ";
$word_landscape_div_end = "</div>";
$content = '<html '.$word_xmlns.'>
<head>
<title>Party Rate Report</title>'
.$word_xml_settings.'<style type="text/css">
'.$word_landscape_style.' table,td
{border:1px solid #FFFFFF; width:200px; color:#CCC;} </style>
</head>
<body>'.$word_landscape_div_start .
'<table style="width:500px; color:#000000;
margin:0 0 50px 100px; font-family: Arial Black, Gadget,
sans-serif; font-size:24px;"><tr><td> Party Rate Report </td>
</tr></table></br>
<table style="width:700px;font-size:15px;font-family:
Arial Black, Gadget, sans-serif;">
<tr>
<td width="180">
Party Name : '. $party_name_row['party_name'] . '
</td>
<td width="250">
Address : '. $party_name_row['party_address'] . '
</td>
<td width="150">
Phone : '. $party_name_row['phone_no']. '
</td>
</tr>
</table><br/>
<table style="width:700px; color:#00000; margin:22px 0 0 0px;
font- family:Helvetica, sans-serif, Verdana;
font-size:15px; border1px solid #666;">
<tr>
<td style=" border:1px solid #666; width:300px;"> Zone</td>
<td style=" border:1px solid #666; width:300px;">
Delivery Mode
</td>
<td style=" border:1px solid #666; width:300px;"> Doc Type </td>
<td style=" border:1px solid #666; width:300px;"> Weight slot </td>
<td style=" border:1px solid #666; width:300px;"> Weight Unit </td>
<td style=" border:1px solid #666; width:300px;"> Flat </td>
<td style=" border:1px solid #666; width:300px;"> Price </td>
</tr>';
$party_details="select *
from tb_party_rate_entry
where party_id=$id";
$query_details=mysql_query($party_details);
while($row_details=mysql_fetch_array($query_details))
{
$content .= '<tr>
<td style=" border:1px solid #666; width:300px;">' .
$row_details['zone_id']. '</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['delivery_mode_id'].'
</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['doc_type_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_slot_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_measure_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
(($row_details['flat'] != '') ? $row_details['flat'] : ' ').'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['price' ] . '</td>
</tr>';
}
$content .= '</table></br>' . $word_xml_settings. $word_landscape_div_end.'
</body>
</html>';
@header('Content-Type: application/msword');
@header('Content-Length: '.strlen($content));
@header('Content-disposition: inline; filename="Party Rate Report.doc"');
echo $content;
}
?>
注意新代码你应该切换到使用mysqli而不是php mysql驱动程序