dongqi9125 2013-09-08 16:32
浏览 22

用于Android应用程序的PHP Web服务已与MySQL连接

I have a problem using this webservice. There are a lot of errors from consultaTipo() and further functions. I think there is a problem with the select in the query statement. Maybe it's how I'm using the variable, but I don't really understand very much from php... I had been trying to search everywhere but... I haven't had any chance to make it work.

<?php
//esta clase permite gestionar la tabla
class DBProducto{
    private $db;

    //en el constructor realizo la conexion
    // a la base de datos
    function __construct(){
        require_once("DBManager.php");
        $this->db = new DBManager();
        $this->db->connect(); //conexion a db
    }
    //destructor
    function __destruct(){}

    //Retornar una coleccion de marcas
    public function consultaMarcas(){
        //$salida = new Array();
        $resultado = mysql_query("SELECT DISTINCT pr_marca".
            "FROM com_productos");
        //obtengo el numero de registros
        $noRegistros = mysql_num_rows($resultado);

        if($noRegistros > 0){
            for($i=0; $row = mysql_fetch_array($resultado); $i++ )
            {
                $salida[] = array($row["pr_id"]=>array("rowId"=>''.$i.'', "marca"=>$row["pr_marca"]));
            }
            return array("datos"=>$salida);
        }else{
            return false;
        }
    }

    // I have the errors from here until the last function

    //Retornar una coleccion de tipos
    public function consultaTipo($mar){
        //$salida = new Array();
        $resultado = mysql_query("SELECT DISTINCT pr_tipo".
            "FROM com_productos WHERE pr_marca = ".$mar);
        //obtengo el numero de registros
        $noRegistros = mysql_num_rows($resultado);

        if($noRegistros > 0){
            for($i=0; $row = mysql_fetch_array($resultado); $i++ )
            {
                $salida[] = array($row["pr_id"]=>array("rowId"=>''.$i.'', "tipo"=>$row["pr_tipo"]));
            }
            return array("datos"=>$salida));
        }else{
            return false;
        }
    }
    //Retornar una coleccion de productos
    public function consultaProductos($tip){
        //$salida = new Array();
        $resultado = mysql_query("SELECT pr_producto,pr_cantidad,pr_descuento,pr_url".
            "FROM com_productos WHERE pr_tipo = ".$tip);
        //obtengo el numero de registros
        $noRegistros = mysql_num_rows($resultado);

        if($noRegistros > 0){
            for($i=0; $row = mysql_fetch_array($resultado); $i++ )
            {
                $salida[] = array($row["pr_id"]=>array("rowId"=>''.$i.'', "productos"=>$row["pr_producto"], "cantidad"=>$row["pr_cantidad"], "descuento"=>$row["pr_descuento"], "url"=>$row["pr_url"]));
            }
            return array("datos"=>$salida);
        }else{
            return false;
        }
    }

    //Retornar una coleccion de cotizaciones
    public function consultaCotizaciones($ced){
        //$salida = new Array();
        $resultado = mysql_query("SELECT cot_nombre, cot_url".
            "FROM com_cotizaciones WHERE cot_cedula = ".$ced);
        //obtengo el numero de registros
        $noRegistros = mysql_num_rows($resultado);

        if($noRegistros > 0){
            for($i=0; $row = mysql_fetch_array($resultado); $i++ )
            {
                $salida[] = array($row["cot_id"]=>array("rowId"=>''.$i.'', "nombre"=>$row["cot_nombre"], "url"=>$row["cot_url"]));
            }
            return array("datos"=>$salida);
        }else{
            return false;
        }
    }
}


?>

Now an example how I pass the variables:

case consultaTipo:
        $dbProductos = new DBProducto();
        $salida = $dbProductos->consultaTipo($_REQUEST('mar'));
        echo json_encode($salida);
        break;

I hope you guys can help me, i really need this working :(

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果