我是PHP新手。我有一个代码,我使用2 sql命令。第一个命令获取第一个最新行,第二个命令获取第二个最新行。此代码位于文件sqlquery.php
这里是sqlquery.php
的代码
<?php
include ("connection.php");
我的代码的问题是我的数组打印相同的记录在所有行。但是在Db中有不同的记录。我的代码是打印每一行的第一个记录
我想输出的代码是这样的
问题是双循环,现在对于第一个查询的每个结果,您为第二个查询的每个结果添加一个数组项,有效地复制数组项,您可以更改
while($row1 = mysql_fetch_assoc($result1)){
while($row2 = mysql_fetch_assoc($result2)){
:
while($row1 = mysql_fetch_assoc($result1) && $row2 = mysql_fetch_assoc($result2))
{
最好改变你的sql查询,虽然合并所有的值在一个请求。
你可以做的另一件事,虽然不太好:
while($row1 = mysql_fetch_assoc($result1))
{
$opinion[]= $row1['opinion'];
$action[]= $row1['atitle'];
$long_term[]= $row1['ltitle'];
$outlook[]= $row1['otitle'];
$rating_type[]= $row1['ttitle'];
$short_term[]= $row1['stitle'];
}
while($row2 = mysql_fetch_assoc($result2))
{
$p_long_term[]= $row2['ltitle'];
$p_short_term[]= $row2['stitle'];
}