PHP代码在本地工作,但在生产时解析错误

时间:2017-08-26 09:51:30

标签: php

if ($_SESSION["readyChatUser"] != "") {?>
                    <div class="portlet box green">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="fa fa-cogs"></i><?php echo $_SESSION["readyChatUser"];?>'s Portfolio </div>
                            <div class="actions">
                                <!--<a href="javascript:;" class="btn btn-default btn-sm">
                                    <i class="fa fa-pencil"></i> Edit </a>-->
                                <a href="#add" data-toggle="modal" class="btn btn-default btn-sm">
                                    <i class="fa fa-plus"></i> Add </a>
                            </div>
                        </div>
                        <div class="portlet-body flip-scroll">
                            <table class="table table-bordered table-striped table-condensed flip-content" id="portfolio">
                                <thead class="flip-content">
                                <tr>
                                    <th width="10%"> # </th>
                                    <th> Name </th>
                                    <th class="numeric"> Price (USD) </th>
                                    <th class="numeric"> Price (BTC) </th>
                                    <th class="numeric"> Change (USD) </th>
                                    <th class="numeric"> Change (%) </th>
                                    <th class="numeric"> Value (USD) </th>
                                    <th class="numeric"> Value (BTC) </th>
                                    <th class="numeric"> Bought at </th>
                                    <th class="numeric"> Amount </th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php



                                $balancesquery = $mysqli->query("SELECT * FROM `tracker` WHERE `userid` = '{$GLOBALS["user"]["user_id"]}'");

                                $balances = array();
                                $total_btc = 0;
                                $total_usd = 0;
                                while($rows = $balancesquery->fetch_array(MYSQLI_BOTH)){
                                    $currency[] = $rows;

                                }
                                foreach($currency as $cryptobalance){
                                    $BTCtoUSD = "https://api.coinmarketcap.com/v1/ticker/{$cryptobalance['currency']} ?>";
                                    $jsonBTC = file_get_contents($BTCtoUSD, false);
                                    $json_data_BTC = json_decode($jsonBTC, true);
                                    $coin = $json_data_BTC[0];
                                    $value_usd = $coin['price_usd'] * $cryptobalance['amount'];
                                    $value_btc = $coin['price_btc'] * $cryptobalance['amount'];
                                    $total_usd = $total_usd + $value_usd;
                                    $total_btc = $total_btc + $value_btc;
                                    $change_usd =  $coin['price_usd'] * $cryptobalance['amount'] - $cryptobalance['start_price'] * $cryptobalance['amount'];
                                    $x = ($cryptobalance['start_price'] * $cryptobalance['amount']);
                                    $y = ($coin['price_usd'] * $cryptobalance['amount']);
                                    $percent = $x/$y;
                                    $change_btc = get_percentage($x,$y) - 100;
                                    ?>
                                    <tr>
                                        <td> <?php echo $counter; ?> </td>
                                        <td> <?php echo $cryptobalance['full_name']; ?> </td>
                                        <td class="numeric"> $ <?php echo $coin['price_usd']; ?> </td>
                                        <td class="numeric"> <?php echo $coin['price_btc']; ?> BTC </td>
                                        <td class="numeric"> $ <?php echo $change_usd; ?> </td>
                                        <td class="numeric"> <?php if($change_usd < 0){ echo   $change_btc;} else{ echo $change_btc;} ?> %</td>
                                        <td class="numeric"> $ <?php echo $value_usd; ?> </td>
                                        <td class="numeric"> <?php echo $value_btc; ?> BTC </td>
                                        <td class="numeric"> $ <?php echo $cryptobalance['start_price']; ?> </td>
                                        <td class="numeric"> <?php echo $cryptobalance['amount']; ?> </td>
                                        <td style=""><center><a href="#delete" data-toggle="modal" id="deletecoin" class="btn btn-circle btn-icon-only btn-default deletecoin">
                                                <i class="icon-trash"></i>
                                            </a></center></td>
                                        <td style="display:none;"><span class="idcrypto" id="coinsid"><?php echo $cryptobalance['id']; ?></span> </td>


                                    </tr>



                                    <?$counter = $counter+1;}
                                ?>

                                </tbody>
                            </table>

                            Total: <span id="totalvalue"><?php echo $total_usd; ?></span> USD = <?php echo $total_btc; ?> BTC
                        </div>
                    </div>
                    <?php } else { ?>
                        <div class="alert alert-block alert-danger fade in">
                            <button type="button" class="close" data-dismiss="alert"></button>
                            <h4 class="alert-heading">Error!</h4>
                            <p> To use LastCrypto's Portfolio Tracker, please log in. </p>
                            <p>

                                <a class="btn blue" href="login.php"> Login </a>
                            </p>
                        </div>
                        <div class="well">

                            <h3>

                            </h3>

                        </div>
                    <?php } ?>

这在我的本地开发机器上完全正常。

但在我的服务器上它给了我

 Parse error: syntax error, unexpected 'else' (T_ELSE)

即使我删除了它提供的else分支

 unexpected end of file

当我删除我刚刚发布的完整部分时,它正常工作没有错误,所以问题必须在那里。 我不知道,请帮帮我。

这是因为不同的php版本或者是什么。我的网站很大,我有类似的网站,工作得很好。

1 个答案:

答案 0 :(得分:0)

短暂的开放就像Codecaster说的那样。感谢