gpt4 book ai didi

PHP mysql 在一个目标中显示 4 个结果

转载 作者:行者123 更新时间:2023-11-29 14:25:13 25 4
gpt4 key购买 nike

我想在 PDF 文件中显示结果。现在的问题是 PDF 文件只能捕获 while 循环的第一行。第一行是否有类似 row[0]['rates'] 的内容,第二行是否有类似 row[1]['rates'] 的内容?因此,我只需获取一次并显示 row[0]['rates']row[1]['rates']...

创建 PDF:

<?php
session_start();

if( empty( $_POST['compare'] ) )
include"connect_to_mysql.php";
$packages = mysql_query("SELECT*FROM package_creation WHERE id IN (". implode(',', $_POST['compare']) ." ) LIMIT 4");

while($row=mysql_fetch_array($packages)){
$compare ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Compare Packages</title>
<style type="text/css">
.print_title{
font-family:Arial, Helvetica, sans-serif;
font-size:20px;
font-weight:bold;
color:#000;
}
.print_text{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
color:#000000;
}
.print_bold{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
color:#000000;
font-weight:bold;
}
.print_footer{
font-family:Arial, Helvetica, sans-serif;
font-size:9px;
color:#000000;
}
.print_big{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#000000;
font-weight:bold;
}
body{
margin:0px;
}
table td{
height:1px;
}
</style>
</head>

<body>
<table class="print_text" align="left">
<tr>
<td width="200px" class="print_bold" align="right">Package</td><td width="100px" class="print_bold" align="center">Package 1</td><td width="100px" class="print_bold" align="center">Package 2</td><td width="100px" class="print_bold" align="center">Package 3</td><td width="100px" class="print_bold" align="center">Package 4</td>
</tr>
<tr>
<td class="print_bold" align="right">Bank Code:</td><td width="100px" align="center">'.$row['bank_name'].'</td><td width="100px" align="center">display 2nd bank</td><td width="100px" align="center">display 3rd bank</td><td width="100px" align="center">display 4th bank</td>
</tr>
</table>
</body>
</html>';

}
include_once('dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html($compare);
$dompdf->render();
$dompdf->stream('Compare_Packages.pdf');

?>

最佳答案

问题是你的 while 循环。每次循环时都会覆盖 $compare 的值。你想要做的事情是这样的

 $compare = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Compare Packages</title>
<style type="text/css">
....//you styles here
</style>
</head>

<body>
<table class="print_text" align="left">
<tr>
<td width="200px" class="print_bold" align="right">Package</td><td width="100px" class="print_bold" align="center">Package 1</td><td width="100px" class="print_bold" align="center">Package 2</td><td width="100px" class="print_bold" align="center">Package 3</td><td width="100px" class="print_bold" align="center">Package 4</td>
</tr>';

while($row=mysql_fetch_array($packages)){

$compare .= '<tr>
<td class="print_bold" align="right">Bank Code:</td><td width="100px" align="center">'.$row['bank_name'].'</td><td width="100px" align="center">display 2nd bank</td><td width="100px" align="center">display 3rd bank</td><td width="100px" align="center">display 4th bank</td>
</tr>';
} //end while

$compare .= '</table>
</body>
</html>';


//rest of your code

这样,它将循环结果添加到 $compare 字符串的中间,而不是每次都覆盖它。查找字符串连接以了解更多详细信息 http://php.net/manual/en/language.operators.string.php 。由于未经测试,如果这里有任何小代码问题,我们深表歉意

关于PHP mysql 在一个目标中显示 4 个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11114531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com