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.
$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.
$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