search with a menu list criteria

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I lost! with this? any one can suggest me some way to do this?,

Now I try this, past all data bye get , and use the temp var with the
query , but I don't have a good results...

$colname_rs_consulta = "a";
if (isset($_GET['buscar'])) {
$colname_rs_consulta = $_GET['buscar'];

if (($_GET['criterio']) == 1) {
$temp = "lb_libros_titulo";
} elseif (($_GET['criterio']) == 2) {
$temp = "lb_libros_autor";

echo $temp;
mysql_select_db($database_editorialconn, $editorialconn);
$query_rs_consulta = sprintf("SELECT * FROM lb_libros WHERE '$temp'
LIKE %s", GetSQLValueString("%" . $colname_rs_consulta . "%",
$query_limit_rs_consulta = sprintf("%s LIMIT %d, %d",
$query_rs_consulta, $startRow_rs_consulta, $maxRows_rs_consulta);
$rs_consulta = mysql_query($query_limit_rs_consulta, $editorialconn)
or die(mysql_error());
$row_rs_consulta = mysql_fetch_assoc($rs_consulta);



Re: search with a menu list criteria

Quoted text here. Click to load it

Things are easier to debug when they are coded in a simple way. Try
again and debug with this:

$colname_rs_consulta = 'a';
if( isset( $_GET['buscar'] ) )
  $colname_rs_consulta =
'%'.mysql_real_escape_string( $_GET['buscar'], $editorialconn ).'%';

if( isset( $_GET['criterio'] ) )
  if( '1' == $_GET['criterio'] )
    $temp = 'lb_libros_titulo';

  else if( '2' == $_GET['criterio'] )
    $temp = 'lb_libros_autor';
 die( 'Criterio es requerido' );

mysql_select_db( $database_editorialconn, $editorialconn );

$query_rs_consulta = "SELECT * FROM `lb_libros` WHERE '$temp' LIKE

$query_limit_rs_consulta = "$query_rs_consulta LIMIT
$startRow_rs_consulta, $maxRows_rs_consulta";

$rs_consulta = mysql_query( $query_limit_rs_consulta, $editorialconn )
  or die( mysql_error() );

//the following should be in a loop condition
$row_rs_consulta = mysql_fetch_assoc( $rs_consulta );

It is also more efficient without sprintf().

-Mike PII

Site Timeline