gpt4 book ai didi

php - 我怎样才能停止 php while 循环一遍又一遍?

转载 作者:行者123 更新时间:2023-11-30 22:40:07 24 4
gpt4 key购买 nike

我有一个 polymer(1.0) 应用程序,我正在尝试创建(基于 stretch-tutorials league table),如果使用 mvc,我无法弄清楚路由,所以我选择了单页站点,引用不同的 php 文件.

我在 MYSql 中有一个表,我试图使用一个简单的回显表脚本将其合并到表中,但这会重复数百次。我怎样才能停止这个循环?

$result = mysql_query('select * from results',$connection) or die('cannot show tables');
while($tableName = mysql_fetch_row($result)) {

$sql = ('SELECT `home_team_name`,`away_team_name`,`home_goals_for`, `away_goals_for`, DATE_FORMAT(`fixture_date`, "%e %M %Y"), TIME_FORMAT(`fixture_time`, "%h:%i %p") FROM `results` ORDER BY fixture_date desc LIMIT 20 '.$table) or die('cannot show columns from '.$table);

echo '<h3>',$table,'</h3>';
$result2 = mysql_query($sql);
if(mysql_num_rows($result2)) {
echo '<table cellpadding="4" cellspacing="0" class="table table-striped table-hover table-bordered">';
echo '<tr class="info"><th>Home team</th><th>Away Team</th><th>Score</th><th>Score</th><th>Date<th>Time</th></tr>';
while($row2 = mysql_fetch_row($result2)) {
echo '<tr>';
foreach($row2 as $key=>$value) {
echo '<td>',$value,'</td>';
}
echo '</tr>';
}
echo '</table><br />';
}
}

我添加了“<50”,但这只返回 50 个表格标题行?

该站点的实时地址为 http://jay-o.uk/#!/results css 和其他数据目前还可以,只是这个讨厌的循环。

最佳答案

嗯..也许你需要这段代码:

// Create an array
$items = array();

while ($row = mysql_fetch_array($resulting, MYSQL_ASSOC)) {
/* print new insert */
var_dump('new item');

/* add a new item */
$items[] = array(
'home_team_name' => $row['home_team_name'],
'away_team_name' => $row['away_team_name'],
'home_goals_for' => $row['home_goals_for'],
'away_goals_for' => $row['away_goals_for']
);
}

$json_response = json_encode($items);
print $json_response;

如果 $json_response 是一个空数组,问题可能是查询没有返回任何行。

关于php - 我怎样才能停止 php while 循环一遍又一遍?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31362982/

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