search with a menu list criteria

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • canagonzales

    #1

    search with a menu list criteria

    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_con sulta = "a";
    if (isset($_GET['buscar'])) {
    $colname_rs_con sulta = $_GET['buscar'];
    }


    if (($_GET['criterio']) == 1) {
    $temp = "lb_libros_titu lo";
    } elseif (($_GET['criterio']) == 2) {
    $temp = "lb_libros_auto r";
    }

    echo $temp;
    mysql_select_db ($database_edit orialconn, $editorialconn) ;
    $query_rs_consu lta = sprintf("SELECT * FROM lb_libros WHERE '$temp'
    LIKE %s", GetSQLValueStri ng("%" . $colname_rs_con sulta . "%",
    "text"));
    $query_limit_rs _consulta = sprintf("%s LIMIT %d, %d",
    $query_rs_consu lta, $startRow_rs_co nsulta, $maxRows_rs_con sulta);
    $rs_consulta = mysql_query($qu ery_limit_rs_co nsulta, $editorialconn)
    or die(mysql_error ());
    $row_rs_consult a = mysql_fetch_ass oc($rs_consulta );

    saludos

    cana

  • Mike P2

    #2
    Re: search with a menu list criteria

    On May 1, 11:58 am, canagonzales <canagonza...@g mail.comwrote:
    echo $temp;
    mysql_select_db ($database_edit orialconn, $editorialconn) ;
    $query_rs_consu lta = sprintf("SELECT * FROM lb_libros WHERE '$temp'
    LIKE %s", GetSQLValueStri ng("%" . $colname_rs_con sulta . "%",
    "text"));
    $query_limit_rs _consulta = sprintf("%s LIMIT %d, %d",
    $query_rs_consu lta, $startRow_rs_co nsulta, $maxRows_rs_con sulta);
    $rs_consulta = mysql_query($qu ery_limit_rs_co nsulta, $editorialconn)
    or die(mysql_error ());
    $row_rs_consult a = mysql_fetch_ass oc($rs_consulta );
    Things are easier to debug when they are coded in a simple way. Try
    again and debug with this:

    <?php
    $colname_rs_con sulta = 'a';
    if( isset( $_GET['buscar'] ) )
    $colname_rs_con sulta =
    '%'.mysql_real_ escape_string( $_GET['buscar'], $editorialconn ).'%';

    if( isset( $_GET['criterio'] ) )
    {
    if( '1' == $_GET['criterio'] )
    $temp = 'lb_libros_titu lo';

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

    mysql_select_db ( $database_edito rialconn, $editorialconn );

    $query_rs_consu lta = "SELECT * FROM `lb_libros` WHERE '$temp' LIKE
    '$colname_rs_co nsulta'";

    $query_limit_rs _consulta = "$query_rs_cons ulta LIMIT
    $startRow_rs_co nsulta, $maxRows_rs_con sulta";

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

    //the following should be in a loop condition
    $row_rs_consult a = mysql_fetch_ass oc( $rs_consulta );
    ?>

    It is also more efficient without sprintf().

    -Mike PII

    Comment

    Working...