By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

search with a menu list criteria

P: n/a
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 . "%",
"text"));
$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);

saludos

cana

May 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 1, 11:58 am, canagonzales <canagonza...@gmail.comwrote:
echo $temp;
mysql_select_db($database_editorialconn, $editorialconn);
$query_rs_consulta = sprintf("SELECT * FROM lb_libros WHERE '$temp'
LIKE %s", GetSQLValueString("%" . $colname_rs_consulta . "%",
"text"));
$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);
Things are easier to debug when they are coded in a simple way. Try
again and debug with this:

<?php
$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';
}
else
die( 'Criterio es requerido' );

mysql_select_db( $database_editorialconn, $editorialconn );

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

$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

May 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.