14 12
发新话题
打印

早上去面试的题目 没做出来

早上去面试的题目 没做出来

1 用PHP获取最后insert插入的记录

2用数据库(mysql)获取insert最后一条记录

3用一个函数 获得输入日期的后一天值时间在 (1921-01-01到2021-12-31)之间

4用大象,小鸟,海豚比做对象 写一个类(例如 大象走路  小鸟飞行)

5数据库有多个同样的数据 多个同样的数据就输出一条 除了用GROUP另一个方法

都是记忆中的一些题目给写下来了  大家帮忙回答一下啦

[ 本帖最后由 chris 于 2007-9-19 21:35 编辑 ]

TOP

复制内容到剪贴板
代码:
1, select * from table_name where id='mysql_insert_id()';

TOP

复制内容到剪贴板
代码:
2, select * from table_name limit 0,1;

TOP

复制内容到剪贴板
代码:
3,
function gettomorrow()
{
$seconds = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
$tomorrow = date("Y-m-d",$seconds);
return $tomorrow;
}
[ 本帖最后由 xinglu1983 于 2007-9-15 21:07 编辑 ]

TOP

这个纯属蒙的,OO的东西还没看懂呢。
复制内容到剪贴板
代码:
4,
<?php

class animal
{
var $animalkind;
function run()
{
echo $this->animalkind." can run.";
}
function fly()
{
echo $this->animalkind." can fly.";
}
function swim()
{
echo $this->animalkind." can swim.";
}
}
$elephant = new animal();
$bird = new animal();
$seapig = new animal();

$elephant->animalkind = 'elephant';
$bird->animalkind = 'bird';
$seapig->animalkind = 'seapig';

$elephant->run();
$bird->fly();
$seapig->swim();
?>

TOP

复制内容到剪贴板
代码:
5, select distinct(name) from table_name;

TOP

对第四个回答一下:
复制内容到剪贴板
代码:
<?php
class Animal {
        public $animal ;
        private $msg = '';
        function __construce ($animal)
        {
                $this->animal=$animal;
                switch($this->animal)
            {
                        case 'bird':        //鸟
                                $this->fly();
                        break;
                        case 'elephant':        //象
                                $this->walk();
                        break;
                        case 'dolphin':                //海豚
                                $this->swim();
                        break;
                }
        }

        function __destruct()
        {
        }

        private function fly()
        {
                $this->halt($this->animal.' can fly');
        }

        private function walk()
        {
                $this->halt($this->animal.' can walk');
        }

        private function swim()
        {
                $this->halt($this->animal.' can swim');
        }

        private function halt($this->msg)
        {
                echo '<pre>';
                print_r($this->msg);
                echo '</pre>';
        }
}

$test=new Animal('bird');
?>
[ 本帖最后由 enze 于 2007-9-17 10:13 编辑 ]

TOP

厉害,哈

TOP

引用:
原帖由 enze 于 2007-9-17 10:11 发表
对第四个回答一下:
有两个地方不太懂

animal为什么要定义成共有的?后面不是有构造函数了吗?(另外__construct写错了哈)
为什么 halt() 的参数用$this->msg 呢?前面定义了msg是个空格,那么halt()不就是永远输出个空格了吗,$this->animal传递不进来。

TOP

回楼上:
1、animal定义为公有是手误,不过没有影响。
2、关于构造函数,我只能汗一个了。后面那个不是构造函数,是析构函数



把代码改一下就可以了。
复制内容到剪贴板
代码:
<?php
class Animal {
        public $animal ;
        function __construct ($animal)
        {
            $this->animal=$animal;
            switch($this->animal)
            {
                    case 'bird':        //鸟
                            $this->fly();
                 break;
                 case 'elephant':        //象
                         $this->walk();
                 break;
                 case 'dolphin':                //海豚
                    $this->swim();
                 break;
             }
        }

        function __destruct()
        {
        }

        private function fly()
        {
                $this->halt($this->animal.' can fly');
        }

        private function walk()
        {
                $this->halt($this->animal.' can walk');
        }

        private function swim()
        {
                 $this->halt($this->animal.' can swim');
        }

        private function halt($msg)
        {
                echo '';
                 print_r($msg);
                 echo '';
        }
}

$test=new Animal('bird');
?>
广告位招租。

TOP

 14 12
发新话题