老师叫我做一个PHP的 双色球选号,
做出来为什么就没有输出数字呢,大家帮帮我吧,
下面是代码.<!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>双色球选号页面</title>
<style type="text/css">
<!--
.x {
height: 5px;
width: 120px;
color: #CCCCFF;
background-color: #6666FF;
font-size: 11px;
float: none;
border: 1px dotted #6699FF;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
.y {
height: 5px;
width: 5px;
color: #CC0000;
background-color: #FF6600;
font-size: 11px;
float: none;
border: 1px dotted #6699FF;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
.z {
height: 5px;
width: 120px;
color: #FFFFFF;
background-color: #FF0000;
font-size: 11px;
float: none;
border: 1px dotted #6699FF;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
.i1 {
height: 12px;
width: 12px;
color: #3366FF;
background-color: #6699FF;
font-size: 11px;
float: none;
border: 2px inset #6666FF;
margin: 0px;
}
.i2 {
height: 16px;
width: 60px;
color: #F0F0F0;
background-color: #FF99FF;
font-size: 11px;
float: none;
margin: 0px;
border: 1px outset #FF00FF;
}
.a {
height: 5px;
width: 225px;
color: #CCCCFF;
background-color: #6666FF;
font-size: 11px;
float: none;
border: 1px dotted #6699FF;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
-->
</style>
</head><body>
<?php
class ssq{
function lan(){
$arr1=array();
while(count($arr1)<=5){
$arr1[]=mt_rand(1,33);
}
echo join(" , ",$arr1);
}function hong(){
$arr2=mt_rand(1,16);
echo $arr2;
}function h(){echo <<< HTML
<table>
  <tr>
<td class='x'>$this->lan()</td>
<td class='y'>$this->hong()</td>
  </tr>
</table>
HTML;}
function sl(){
$x=$_POST['t'];
for($i=1;$i<=$x;$i++){
$this->h();
echo "<br>";
}
}}?>
<form id="form1" name="form1" method="post" action="">
  <label></label>
  <table width="206" class="a">
    <tr>
      <td width="123">请输入您要购买的数量:</td>
      <td width="23"><input name="t" type="text" class="i1" id="textfield" size="2" maxlength="2" /></td>
      <td width="60"><input class="i2"type="submit" name="button" id="button" value="点击选号" /></td>
    </tr>
  </table>
</form>
<?php
$xx=new ssq();
$xx->sl();
?>
</body>
</html>

解决方案 »

  1.   

    echo <<< HTML
            <table>
              <tr>
                <td class='x'>$this->lan()</td>
                <td class='y'>$this->hong()</td>
              </tr>
            </table>
    HTML;
    改成
    echo <<< HTML
            <table>
              <tr>
                <td class='x'>{$this->lan()}</td>
                <td class='y'>{$this->hong()}</td>
              </tr>
            </table>
    HTML;
      

  2.   

    楼上说的对,但是还有点不地的地方,应该改成:
    echo " HTML 
            <table> 
              <tr> 
                <td class='x'>{$this->lan()} </td> 
                <td class='y'>{$this->hong()} </td> 
              </tr> 
            </table> 
    HTML";这样就对了.
      

  3.   

    <!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=gb2312" />
    <title>双色球选号页面</title>
    <style type="text/css">
    <!--
    .x {
        height: 5px;
        width: 120px;
        color: #CCCCFF;
        background-color: #6666FF;
        font-size: 11px;
        float: none;
        border: 1px dotted #6699FF;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: 0px;
    }
    .y {
        height: 5px;
        width: 5px;
        color: #CC0000;
        background-color: #FF6600;
        font-size: 11px;
        float: none;
        border: 1px dotted #6699FF;
            margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: 0px;
    }
    .z {
        height: 5px;
        width: 120px;
        color: #FFFFFF;
        background-color: #FF0000;
        font-size: 11px;
        float: none;
        border: 1px dotted #6699FF;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: 0px;
    }
    .i1 {
        height: 12px;
        width: 12px;
        color: #3366FF;
        background-color: #6699FF;
        font-size: 11px;
        float: none;
        border: 2px inset #6666FF;
        margin: 0px;
    }
    .i2 {
        height: 16px;
        width: 60px;
        color: #F0F0F0;
        background-color: #FF99FF;
        font-size: 11px;
        float: none;
        margin: 0px;
        border: 1px outset #FF00FF;
    }
    .a {
        height: 5px;
        width: 225px;
        color: #CCCCFF;
        background-color: #6666FF;
        font-size: 11px;
        float: none;
        border: 1px dotted #6699FF;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: 0px;
    }
    -->
    </style>
    </head><body>
    <?php
    class ssq{
    function lan(){
            $arr1=array();
            while(count($arr1)<=5){
            $arr1[]=mt_rand(1,33);
            }
            return join(" , ",$arr1);
        }function hong(){
            $arr2=mt_rand(1,16);
            return $arr2;
        }function h(){
    echo <<< HTML
            <table>
              <tr>
                <td class='x'>{$this->lan()}</td>
                <td class='y'>{$this->hong()}</td>
              </tr>
            </table>
    HTML;}
    function sl(){
        $x=$_POST['t'];
        for($i=1;$i<=$x;$i++){
            $this->h();
            echo "<br>";
        }
        }}?>
    <form id="form1" name="form1" method="post" action="">
      <label></label>
      <table width="206" class="a">
        <tr>
          <td width="123">请输入您要购买的数量:</td>
          <td width="23"><input name="t" type="text" class="i1" id="textfield" size="2" maxlength="2" /></td>
          <td width="60"><input class="i2"type="submit" name="button" id="button" value="点击选号" /></td>
        </tr>
      </table>
    </form>
    <?php
    $xx=new ssq();
    $xx->sl();
    ?>
    </body>
    </html>错误1:
    我第一次运行没有打开页面。你的网页是中文字符却用了UTF-8字符集。不知道你这里怎么显示的,我这里是一片乱码。修改成GB2312后正常错误2:
    字符串中注意歧义。PHP读到$this->lan后停止读取。以为他是一个变量。当然调用失败了。需要加花括号区分。代码一点都不规范,还需要好好提高!!
      

  4.   


    这位同学。你连 <<< 符号都没有理解