我有一个小的php类,我对它进行了一些编辑,以提出我的问题。这个类如下所示
class Register
{
public $notification = null;
public function __construct()
{
create_connection();
$this->validate_register();
}
public function validate_register()
{
//edit: missing double quote close
$select_register = "SELECT * FROM `student_reg`";
if($select_register_run = mysql_query($select_register))
{
$rows_returned = mysql_num_rows($select_register_run);
if($rows_returned >= 1)
{
$this->notification = 'error';
}else if($rows_returned == 0){
$this->notification = 'success';
}
}else{
$this->notification = 'error';
}
if($this->notification != null)
{
echo 'not null';
}else{ echo 'null';}
}
}
$new_register = new Register();
?>很明显,在类中,在任何可能的级别上,都有一个赋给$this->notification的值。但是由于某些原因,这个类'echoes‘为null。
我构建的creat_connection()函数运行得很好,但我在这个问题中省略了它。
为什么会这样呢?
发布于 2014-03-14 21:39:26
实际上,如果$rows_returned小于1且不等于0,则代码将回显'null',因此我建议您回显$rows_returned。
发布于 2014-03-14 21:44:28
试着这样..。
$select_register_run = mysql_query($select_register);
if($select_register_run){
//rest code而不是
if($select_register_run = mysql_query($select_register))https://stackoverflow.com/questions/22406262
复制相似问题