Where do I get my mysql_num_rows() from my class?

Discussion in 'PHP' started by piropeator, Mar 14, 2011.

  1. #1
    I have my table Articulo with three fields:
    Id (Autoincrement/Primary Key)
    codigo (Unique)
    nombre

    I want to enter a code (codigo) and find if this code already exist in my table (Articulo). If exist run template1, if doesn't exist run template2.

    verificar.php:
    <?php
    require_once "../config.php";
    $dao = new ArticuloClass();
    $u = $dao->verificar($_POST['codigo']);
    
    ...... I want to put here is mysql_num_rows=1 or mysql_num_rows=0;
    
    
    PHP:
    ArticuloClass.php
    <?php
    class ArticuloDAO {
        function ArticuloDAO() {
        }
        function verificar($criterio){
           $query = "SELECT id, codigo, nombre FROM articulos WHERE codigo = '$criterio'";
           $BD = new ConexionDB();
           $recordSet = $BD->dbLink->Execute($query);
           if (!$recordSet){
                            Debug::println("No se pudo ejecutar la consulta Verificar: " . $query);
                            return false;
                           }
           return mysql_num_rows($recordSet);   [B][COLOR="red"]/// REturn if exist or not[/COLOR][/B]
        }
    
    
    PHP:
    The query run here ConexionDB.Class.php:
    <?php
    require_once ADODB_BASEFILE;
    class ConexionDB {
        var $dbLink;
        function ConexionDB(){
            $this->dbLink = ADONewConnection(DB_TYPE);
            $this->dbLink->SetFetchMode(ADODB_FETCH_ASSOC);
            $dbconnected = $this->dbLink->PConnect(DB_HOST, DB_USER, DB_KEY, DB_DATA);
            if (!$dbconnected){
                Debug::println('No se pudo conectar a la Base de Datos');
                exit(0);
            }            
        }    
    }
    ?>
    PHP:
    This code use smarty/php.
    I hope somebody can help me.
     
    piropeator, Mar 14, 2011 IP
  2. hypokill

    hypokill Well-Known Member

    Messages:
    271
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    
    $qu = mysql_query("SELECT * FROM articulos WHERE codigo = '$_POST['codigo']'");
    $outcome = mysql_num_rows($qu);
    if ($outcome == 0){
    echo "There was no entry in the database";
    } else {
    echo "There was an entry";
    }
    
    Code (markup):
    Should be what you want.
     
    hypokill, Mar 14, 2011 IP
  3. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #3
    Excellent, but your code where I put inside my code ??
     
    piropeator, Mar 15, 2011 IP
  4. hypokill

    hypokill Well-Known Member

    Messages:
    271
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    
    $qu = mysql_query("SELECT * FROM articulos WHERE codigo = '$_POST['codigo']'");
    $outcome = mysql_num_rows($qu);
    if ($outcome == 0){
    //If there are no results then edit this here
    echo "There was no entry in the database";
    } else {
    //If there is a match then edit this
    echo "There was an entry";
    }
    
    Code (markup):
    Hope that helps
     
    hypokill, Mar 15, 2011 IP