PHP 不执行,即使它读取变量

Posted

技术标签:

【中文标题】PHP 不执行,即使它读取变量【英文标题】:PHP does not execute, even though it reads variables 【发布时间】:2016-11-06 09:39:08 【问题描述】:

我有一个 php 文件,我希望用户从两个下拉列表中选择值,然后提交一些要执行的代码。测试后我注意到,它读取第一个回显,它通知用户选择了这两个特定值,但所有其他代码,应该显示这两个值的连接,不执行。我觉得我很接近,但我认为我需要一些推动。下面是代码

<form method="GET" action="">
    <table>
    <tr><br /><br /><center><h2>Επιλέξτε τις ομάδες για τις οποίες θέλετε να δείτε το ιστορικό</h2><center><br /></tr>
    <tr>
    <td><i>Επιλογή 1ης ομάδας</i></td>
    <td>
        <select id="Team1" name="Team1"><option value="0">Καμία επιλογή</option>
        <?php
global $wpdb;
$table = $wpdb->prefix . 'leagueengine_data';
$table2 = $wpdb->prefix . 'leagueengine_tournament_matches';
$teams = $wpdb->get_results("SELECT * FROM $table WHERE data_type = 'team' ORDER BY data_value ASC");
foreach ( $teams as $teams ) 
   $team_id = $teams->id;
$team_name = $teams->data_value;
echo '<option value="'.$team_id.'">'.leagueengine_fetch_data_from_id($teams->id,'data_value') .'</option>';

$output .= '</div>';
?>  
</select>
</td></tr>
<tr>
    <td><i>Επιλογή 2ης ομάδας</i></td>
    <td>
        <select id="Team2" name="Team2"><option value="0">Καμία επιλογή</option>
        <?php
global $wpdb;
$table = $wpdb->prefix . 'leagueengine_data';
$table2 = $wpdb->prefix . 'leagueengine_tournament_matches';
$teams2 = $wpdb->get_results("SELECT * FROM $table WHERE data_type = 'team' ORDER BY data_value ASC");
foreach ( $teams2 as $teams2 ) 
   $team2_id = $teams2->id;
$team2_name = $teams2->data_value;
echo '<option value="'.$team2_id.'">'.leagueengine_fetch_data_from_id($teams2->id,'data_value') .'</option>';

$output .= '</div>';
 ?> 
 </select>
 </td></tr>
 </table>

<input type="submit" value="Αναζήτηση ιστορικού"><br />
</form>
<?php
$teamhome = mysql_real_escape_string($_GET['Team1']);
$teamaway = mysql_real_escape_string($_GET['Team2']);
$table2 = $wpdb->    prefix . 'leagueengine_tournament_matches';

 echo '<div id="show">';

  if (isset($_GET["Team2"])) 
echo "<center>Επιλέξατε να δείτε την προϊστορία μεταξύ των ομάδων"; 

  echo '<b> '.leagueengine_fetch_data_from_id($teamhome, 'data_value').'</b>';
  echo ' και <b>'.leagueengine_fetch_data_from_id($teamaway, 'data_value').'</b></center>'; 
    $gbeet = $wpdb->get_var("SELECT count(*) FROM $table2 WHERE home_team_id = '$teamhome' AND away_team_id = '$teamaway' AND winner <> '' OR  home_team_id = '$teamaway' AND away_team_id = '$teamhome' AND winner <> ''");
    $home_team_wins = $wpdb->get_var("SELECT COUNT(*) FROM $table2 WHERE (home_team_id = '$teamhome' AND away_team_id = '$teamaway' or home_team_id = '$teamaway' AND away_team_id = '$teamhome') AND winner = '$teamhome'");
    $away_team_wins = $wpdb->get_var("SELECT COUNT(*) FROM $table2 WHERE (home_team_id = '$teamhome' AND away_team_id = '$teamaway' or home_team_id = '$teamaway' AND away_team_id = '$teamhome') AND winner = '$teamaway'");
    $homepnts1 = $wpdb->get_var("SELECT SUM(home_team_score) FROM $table2 WHERE home_team_id = '$teamhome' AND away_team_id = '$teamaway' AND winner <> ''");
    $homepnts2 = $wpdb->get_var("SELECT SUM(away_team_score) FROM $table2 WHERE home_team_id = '$teamaway' AND away_team_id = '$teamhome' AND winner <> ''");
    $homepnts= ($homepnts1) + ($homepnts2);
    $awaypnts1 = $wpdb->get_var("SELECT SUM(home_team_score) FROM $table2 WHERE home_team_id = '$teamaway' AND away_team_id = '$teamhome' AND winner <> ''");
    $awaypnts2 = $wpdb->get_var("SELECT SUM(away_team_score) FROM $table2 WHERE home_team_id = '$teamhome' AND away_team_id = '$teamaway' AND winner <> ''");
    $awaypnts= ($awaypnts1) + ($awaypnts2);



    $output .= '<br/><h2><center><b>Αναμετρήσεις ομάδων</b></center></h2>';
    $output .= '<span><center><i>Οι ομάδες έχουν βρεθεί αντιμέτωπες <b>'.$gbeet.'</b> φορές.</i></center></span>';
    $output .= '<table class="tournament_match_attributes">';

$output .= '<tbody><tr>';
$output .= '<th  style="text-align:center;"><b>'.leagueengine_fetch_data_from_id($teamhome, 'data_value').'</b></th>';
$output .= '<th ></th>';
$output .= '<th  style="text-align:center;"><b>'.leagueengine_fetch_data_from_id($teamaway, 'data_value').'</b></th>';
$output .= '</tr><tr>';
$output .= '<td>'.$home_team_wins.'</td>';
$output .= '<td><b>Νίκες</b></td>';
$output .= '<td>'.$away_team_wins.'</td>';
$output .= '</tr><tr>';
$output .= '<td>'.$homepnts.'</td>';
$output .= '<td><b>Πόντοι</b></td>';
$output .= '<td>'.$awaypnts.'</td>';
$output .= '</tr></tbody>';

                $output .= '</table>';

                $output .= '<table class="tournament_match_attributes">';
                $games = $wpdb->get_results("SELECT * FROM $table2 WHERE home_team_id = '$teamhome' AND away_team_id = '$teamaway' AND winner <> '' OR home_team_id = '$teamaway' AND away_team_id = '$teamhome' AND winner <> '' ORDER BY match_date DESC;");


$output .= '<tbody><tr>';
$output .= '<th style="text-align:center;"><b>Τουρνουά</b></th>';
$output .= '<th style="text-align:center;"><b>Ημερομηνία</b></th>';
$output .= '<th style="text-align:center;"><b>Αγώνας</b></th>';
$output .= '<th style="text-align:center;"><b>Σκορ</b></th></tr>';
foreach($games as $games) 
$date_of_match = $games->match_date;
$dom = date("d/m/Y", strtotime($date_of_match));
$Ateam = leagueengine_fetch_data_from_id($games->home_team_id,'data_value') ;
$Bteam = leagueengine_fetch_data_from_id($games->away_team_id,'data_value') ;
$Ascore = $games->home_team_score;
$Bscore = $games->away_team_score;
$tourne = leagueengine_fetch_data_from_id($games->tournament_id,'data_value') ;


$output .= '<tr><td>' .$tourne. '</td>';
$output .= '<td>'.$dom. '</td>';
$output .= '<td>'.$Ateam.' - '.$Bteam.'</td>';
$output .= '<td>'.$Ascore.' - '.$Bscore.'</td>';
$output .= '</tr>';

$output .= '<tr></tbody>';

                $output .= '</table>';
  
                ?>

【问题讨论】:

foreach ( $teams2 as $teams2 ) 更改为foreach ( $teams2 as $team2 ) 并在$team2 中使用$team2 并检查。 我测试过了。通过此更改,它甚至停止生成 2 个列表。 此点以下不执行任何代码 --> $gbeet = ..... 【参考方案1】:

真的很抱歉没用,因为它似乎是帖子。在我用 echo 替换输出之后,一切都解决了:/

【讨论】:

以上是关于PHP 不执行,即使它读取变量的主要内容,如果未能解决你的问题,请参考以下文章

完成处理程序不返回任何内容,即使它看起来像在单步执行时

在 PHP 脚本中处理错误并继续执行

php长时间执行挂起现象怎么解决?

在 SQL 中检查 IF 条件,即使它不匹配

即使在从python脚本执行linux脚本后,也永久设置环境变量

PHP-CLI环境变量的设置和读取