为什么输出不了号码呢?

chilychang 2010-01-05 03:39:06
老师叫我做一个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>

...全文
96 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
苍蝇①号 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jiewenxu 的回复:]
引用 2 楼 standford 的回复:
楼上说的对,但是还有点不地的地方,应该改成:
echo " HTML
         <table>
           <tr>
             <td class='x'>{$this->lan()}  </td>
             <td class='y'>{$this->hong()}  </td>
           </tr>
         </table>
HTML";

这样就对了.


这位同学。你连 < < < 符号都没有理解
[/Quote]
是啊二楼这位仁兄得注意下了,别发错贴,使问题复杂化
jiewenxu 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 standford 的回复:]
楼上说的对,但是还有点不地的地方,应该改成:
echo " HTML
        <table>
          <tr>
            <td class='x'>{$this->lan()} </td>
            <td class='y'>{$this->hong()} </td>
          </tr>
        </table>
HTML";

这样就对了.
[/Quote]

这位同学。你连 <<< 符号都没有理解
jiewenxu 2010-01-05
  • 打赏
  • 举报
回复
<!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后停止读取。以为他是一个变量。当然调用失败了。需要加花括号区分。

代码一点都不规范,还需要好好提高!!
standford 2010-01-05
  • 打赏
  • 举报
回复
这个还是有个问题,你这个规则不符合双色球的规则啊,哈哈,再做进一步的优化会更好.还是建议看看双色球的规则.
standford 2010-01-05
  • 打赏
  • 举报
回复
楼上说的对,但是还有点不地的地方,应该改成:
echo " HTML
<table>
<tr>
<td class='x'>{$this->lan()} </td>
<td class='y'>{$this->hong()} </td>
</tr>
</table>
HTML";

这样就对了.
satanzhf 2010-01-05
  • 打赏
  • 举报
回复
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;

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧