PHP Classes

Column ambiguous

Recommend this page to a friend!

      Eyesis Data Grid Control  >  All threads  >  Column ambiguous  >  (Un) Subscribe thread alerts  
Subject:Column ambiguous
Summary:Column ambiguous
Messages:4
Author:Alejandro Borrego
Date:2009-04-21 13:26:40
Update:2010-12-16 22:57:34
 

  1. Column ambiguous   Reply   Report abuse  
Picture of Alejandro Borrego Alejandro Borrego - 2009-04-21 13:26:40
Good morning guys, I've been using this powerful class, and now I am in problem.

How to troubleshoot the problem that occurs when trying to filter a column: "Column 'name' in where clause is ambiguous" knowing that I have two tables: country, state, which both have a field called "name" and I want to filter by any of the two fields ..

thanks for your attention. I hope your answer.

  2. Re: Column ambiguous   Reply   Report abuse  
Picture of Alejandro Borrego Alejandro Borrego - 2009-05-15 18:38:59 - In reply to message 1 from Alejandro Borrego


$x->setQuery("idestado, e.nombre as nombre, p.nombre as nombre2", "estado as e, pais as p","idestado","e.idpais=p.idpais");

public function select($fields, $table, $where = false, $orderby = false, $limit = false){....
..
$this->query("SELECT " . $fields . " FROM " . $table . " " . $where . $orderby . $limit);
... }

public function fieldName2($fields)
{
$arreglo_campos= ("array( ");

$arre = split(",",$fields); //separo campos por comas
for($i = 0; $i <= count($arre); $i++){
$arre2 = split(" ",trim($arre[$i])); //separo campo de su alias SI es q existe.

$arreglo_campos .= ("'".$arre2[0]."',"); //armo el array
}
$arreglo_campos=substr($arreglo_campos, 0, -1); //elimino coma(,) al final de la cadena
$arreglo_campos.= (" );"); //cierro el arreglo
eval("\$arreglo_campos = $arreglo_campos"); //convierto la cadena a arreglo
return $arreglo_campos;

}

  3. Re: Column ambiguous   Reply   Report abuse  
Picture of Alejandro Borrego Alejandro Borrego - 2009-05-15 18:53:35 - In reply to message 1 from Alejandro Borrego

Step 2

modify the function fieldNameArray()

public function fieldNameArray($query = false, $fields = false)
{
$names = array();

$field = $this->countFields($query);

$arreglo_camp = $this->fieldName2($fields);
for ( $i = 0; $i < $field; $i++ )
$names[] = $arreglo_camp[$i] ;

return $names;
}

Step 3
modify class.eyedatagrid.inc.php

Step 4
modify function
private function buildHeader(){...

line
$headers = $this->_db->fieldNameArray($this->result);
by
$headers = $this->_db->fieldNameArray($this->result, $this->select_fields);

Step 5
modify function printTable()

line
$filter_query .= "(`" . $this->filter['Column'] . "` LIKE '" . $filter_value . "')";
by
$filter_query .= "(" . $this->filter['Column'] . " LIKE '" . $filter_value . "')";


line
if ($this->order)
$order = "ORDER BY `" . $this->order['Column'] . "` " . $this->order['Order'];

by
if ($this->order)
$order = "ORDER BY " . $this->order['Column'] . " " . $this->order['Order'];


Finally, try the query again to see the changes.

thus achieved by solving the problem solution to the question posed at the beginning, we would appreciate if anyone has a better option and wants to share.

  4. Re: Column ambiguous   Reply   Report abuse  
Picture of davo24 davo24 - 2010-12-16 22:57:34 - In reply to message 3 from Alejandro Borrego
oye un favor me sirvio mucho tu modificacion para mi proyecto pero en encabezado en el nombre de la columna me aparece por ejemplo estudiante.nombre y yo solo quiero que me aparezca un alias y lo puse en la consulta estudiante.nombre as nombre pero me sigue apareciendo todo completo te agradeceria si pudieras ayudar.