小编Vic*_*cky的帖子

如何使用PHP中的JS原型从Select html元素中检索值?

<script type="text/javascript" src="prototype.js"></script>
    <script>
    function reload(form){
    var val = $("seltab");alert(val);
    }</script>
echo "<form method = post name = f1 action = '' >";
    echo "<select id = seltab onchange =  'reload(this.form)'>";
        $querysel = "SELECT title_id,author FROM authors NATURAL JOIN books";
    $result1 = mysql_query($querysel) ;
    while($rowID = mysql_fetch_assoc($result1))
    {
        $TitleID = $rowID['title_id'];
        $author = $rowID['author'];
        print "<option value =$TitleID>$author\n";
        print "</option>";
    }
    print "</select>";
Run Code Online (Sandbox Code Playgroud)

javascript php prototypejs

3
推荐指数
1
解决办法
1万
查看次数

不在对象上下文时使用$ this - 我使用的是最新版本的php和mysql

这是user.php:

    include("databse.php");//retrieving successfully first name and lastname from databse file into user.php
    class user
    {
      public $first_name;
      public $last_name;
      public static function full_name()
      {
          if(isset($this->first_name) && isset($this->last_name))
          {
            return $this->first_name . " " . $this->last_name;

          }
          else
           {
                return "";
           }
       }
    }
Run Code Online (Sandbox Code Playgroud)

其他php文件,index.php:

   include(databse.php);
   include(user.php);
    $record = user::find_by_id(1);
    $object = new user();
    $object->id = $record['id'];
    $object->username = $record['username'];
    $object->password = $record['password'];
    $object->first_name = $record['first_name'];
    $object->last_name = $record['last_name'];
    // echo   $object->full_name();
    echo $object->id;// successfully print the id
    echo $object->username;//success fully …
Run Code Online (Sandbox Code Playgroud)

php

2
推荐指数
1
解决办法
286
查看次数

标签 统计

php ×2

javascript ×1

prototypejs ×1