本帖最后由 clown7ools 于 2012-11-17 05:09:55 编辑

解决方案 »

  1.   

    n种方法:首先,a页面应该是个表单。
    通过表单把用户输入提交到b页面。b页面得到值后,调用c页面。问题就在这。你也说了,c是个类。那么b页面include c页面,把c页面中的类实例化,然后调用它的方法来处理数据然后方法将值返回给b页面不就行了?为什么一定要把值传给c让它处理?a.html
    -------------------
    <form method='post' action='b.php'>
    <input type='text' name='txt' />
    </form>b.php
    --------------------
    <?php
    include 'c.php';
    $result = c::change( $_POST['txt'] );
    echo $result;
    c.php
    ---------------------
    <?php
    class c{
        public static function change( $txt ){
              ....
              return $txt;
        }
    }
      

  2.   

    其次,如果非要按你说的,让b把值交给c,让它来处理再返回给b,也可以。a.html
    -------------------
    <form method='post' action='b.php'>
    <input type='text' name='txt' />
    </form>b.php
    --------------------
    <?php
    function request( $url, $data ){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $response = curl_exec($ch);
        $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $response;
    }

    echo request( 'http://localhost/c.php', 'txt='.$_POST['txt'] );
    c.php
    ---------------------
    <?php
    class c{
        public static function change( $txt ){
              ....
              return $txt;
        }
    }echo c::change( $_POST['txt'] );我还是建议你用第一种。
      

  3.   

    是这样的, 我需要对字符进行处理。
    假如B页面从A页面中取得 $_post['select']
    为了页面代码整洁。我希望使用C页面的类进行处理。比如:
    class list_number{
    var $a,$b;
    public function Number($a,$b){
    $this->a=$a;
    $this->b=$b;


    switch ($this->a){
    case $this->a==1;
    $this->b=$this->b;
    return $this->a;
    return $this->b;
    break;
    case $this->a==2;
    $this->b="Files_Introduction";
    return $this->a;
    return $this->b;
    break;
    case $this->a==3;
    $this->b="Files_UploadTime";
    return $this->a;
    return $this->b;

    break;
    default;
    echo "程序出错!请联系管理员!";
    }

    }B页面进行实例化。$Number=(int)$_POST['select'];
    $list_Number= new list_number();
    $list_Number->Number($Number,$Where,$Keyword);
    那么我又纠结了。 处理好的$a,$b我怎么在B页面使用。?
      

  4.   

    上面实例化代码错了。 我重新弄一下。
    B.php<?php include("class/Number.php"); ?><?php 
    if (isset($_POST['Search'])){
    $Number=(int)$_POST['select'];
    $Keyword=$_POST['keyword'];
    $Where="Files_Name";
    if(trim($Keyword)){
    /*
    $s = new list_number();
    $a = unserialize($s);
    $a->keyword();
    */
    $list_Number= new list_number();
    $list_Number->Number($Number,$Where,$Keyword); }

    }
    else{
    header("Location: http://localhost/"); 
    }
    ?>C页面代码<?php 
    class list_number{
    var $a,$b,$c,$d;
    public function Number($a,$b,$c){
    $this->a=$a;
    $this->b=$b;
    $this->c=$c;

    switch ($this->a){
    case $this->a==1;
    $this->b=$this->b;
    return $this->a;
    return $this->b;
    break;
    case $this->a==2;
    $this->b="Files_Introduction";
    return $this->a;
    return $this->b;
    break;
    case $this->a==3;
    $this->b="Files_UploadTime";
    return $this->a;
    return $this->b;

    break;
    default;
    echo "程序出错!请联系管理员!";
    }

    }

    public function keyword(){
    if ($this->c){
    $pattern = "/[ '.,:;*?~`!@#$%^&+=\-)(<>{}]|\]|\[|\/|\\\|\"|\|/";  
    $this->c= preg_replace($pattern," ", $this->c); 
    $pattern2 = "/[’。,:;*?~·!@#¥%……&+()、\-)(<>{}]|\]|\[|\/|\\\|\"|\|/";  
    $this->c= preg_replace($pattern2," ",$this->c);
    $this->c= explode(" ",$this->c);
    //print_r($this->c).'<br />';

     if(is_array($this->c)){
      foreach ($this->c as $key => $value) {
    $value= trim($value);
    if($value==""){
    unset($this->c[$key]);
    }
    }
    print_r($this->c);
     }
     
    }
    }
    }?>
    我想使用C页面处理好的数据,然后代入SQL数据库查询。
    但是不知道怎么去做! 求解释。 谢谢! 
      

  5.   

    你的 list_number::Number 方法只对第二个参数做了改动,所以
    应删去所有的 return $this->a; 只保留 return $this->b;
    调用时的
    $list_Number->Number($Number,$Where,$Keyword);
    改为
    $Where = $list_Number->Number($Number,$Where,$Keyword);
    这样 $Number、$Where、$Keyword 就可以用于组装 SQL 串了
      

  6.   


    请问一下,按照您说的那样做。$Where 是什么类型的数据了?
    是不是这样调用。
    $sql='select * from table where classid ='.$Where.' limit 0,10';怎么样查看他呢。 echo ? print_r ?
      

  7.   

    $sql = "select * from table where classid ='$Where' limit 0,10";按照你的代码
    $Where 的取值是
    不变
    Files_Introduction
    Files_UploadTime
    之一echo $sql;
    就可看到
      

  8.   


    测试了下,是可以的。但是只能看到一个值,最后一个问题!
    如何获取指定的,比如说,Number($a,$b)
    我只想要$a、$b或者全部。?
      

  9.   

    $list_Number->Number($Number,$Where,$Keyword);
    $a = $list_Number->a;
    $b = $list_Number->b;
    $c = $list_Number->c;
      

  10.   

    属性!
    class list_number{
                var $a,$b,$c,$d;