对不起球员,我读和搜索在网上,我无法找到这个:(一个解决方案。 如果可以请帮我:)谢谢。
如果我硬code 位置,然后它工作得很好。我已经尝试过这几种不同的方法......
P.S。 我要创建某种图片库AJAX页面锻炼:)我认为这位置变量应该是在单/静态类我猜。我没能尚未测试这个类,但我认为这将只对第一个和最后一个图像总是:)(在Java code这将是很容易做到的:))。
错误: 的通知:未定义的变量:位置在D:\瓦帕\的www \在线11测试\ gethint.php
< PHP 类指数{ 私人$位置= 1; 下一个公开函数(){ 返回$位置++ ;; } 公共职能preV(){ 返回$ position--; } 公共功能复位(){ $位置= 1; 返回$地位; } } $行动= $ _ REQUEST [行动]; $指数= 0; 如果($行动!= 1){ $指数=指数:: preV(); } 其他 { $指数=指数::接下来的(); } 如果($指数< 1){ $指数= 7; } 如果($指数大于7){ $指数= 1; } $回应=。< IMG的边界= \0 \SRC = \$指数。JPG \ALT = \$指数。\WIDTH = \500 \高度= \ 334 \>中; 回声$反应; ?>解决方案
改变这一行
返回$位置++ ;;
到
返回$位置++; // 额外 ;和这样的访问类变量
$这个 - >仓位++; //不是$位置有关创建静态变量使用静态关键字
私有静态$位置= 1;有关访问静态变量使用
自:: $地位;
改变这种
如果($行动!= 1){ $指数=指数:: preV(); } 其他 { $指数=指数::接下来的(); }
到
$ =中新指数(); 如果($行动!= 1){ $指数= $ IN-> preV(); } 其他 { $指数= $ IN - >接下来(); }Sorry guys, I am reading and searching over the web and I cannot find a solution for this :(. If you can please help me :) Thanks.
If I hard code position then it works well. I already tried this on several different ways...
P.S. I have to create some kind of image gallery ajax page for exercise :) I assume this position variable should be in singleton/static class i guess. I was not able to test this class yet, but I think this will work only for first and last image always :) (in java code this would be very easy to do :) ).
Error: Notice: Undefined variable: position in D:\Wamp\www\test\gethint.php on line 11
<?php class Index { private $position=1; public function next(){ return $position++;; } public function prev(){ return $position--; } public function reset(){ $position=1; return $position; } } $action=$_REQUEST["action"]; $index = 0; if($action!=1){ $index=Index::prev(); } else { $index=Index::next(); } if($index < 1){ $index=7; } if($index > 7){ $index=1; } $response="<img border=\"0\" src=\"".$index.".jpg\" alt=\"".$index."\" width=\"500\" height=\"334\">"; echo $response; ?>解决方案
change this line
return $position++;;to
return $position++; // extra ;and access class variable like this
$this->position++; // not $positionfor creating static variable use static keyword
private static $position=1;for accessing static variable use
self::$position;change this
if($action!=1){ $index=Index::prev(); } else { $index=Index::next(); }to
$in = new Index(); if($action!=1){ $index= $in->prev(); } else { $index= $in->next(); }
更多推荐
未定义的变量:位置
发布评论