Pessoal.
Presciso de uma tela de consulta a clientes e outra que mostre os resultados. Quando crio as Querys no dreamweaver, oresultado é satisfatório. Quando faço a pesquisa a partir da página busca.php, a página resultados.php aparece apenas com a tabela vazia. Estou usando URL Parameter para passar o dado de uma página para outra. Imagino que seja um erro "besta", mas não consegui descobrikr o mistério.
Segue o código da página resultados.php:
[codebox]$maxRows_resultados = 10;
$pageNum_resultados = 0;
if (isset($_GET['pageNum_resultados'])) {
$pageNum_resultados = $_GET['pageNum_resultados'];
}
$startRow_resultados = $pageNum_resultados * $maxRows_resultados;
$colname_resultados = "-1";
if (isset($_GET['nome'])) {
$colname_resultados = $_GET['nome'];
}
mysql_select_db($database_conection, $conection);
$query_resultados = sprintf("SELECT nome, cpf FROM cadcli WHERE nome = %s", GetSQLValueString($colname_resultados, "text"));
$query_limit_resultados = sprintf("%s LIMIT %d, %d", $query_resultados, $startRow_resultados, $maxRows_resultados);
$resultados = mysql_query($query_limit_resultados, $conection) or die(mysql_error());
$row_resultados = mysql_fetch_assoc($resultados);
if (isset($_GET['totalRows_resultados'])) {
$totalRows_resultados = $_GET['totalRows_resultados'];
} else {
$all_resultados = mysql_query($query_resultados);
$totalRows_resultados = mysql_num_rows($all_resultados);
}
$totalPages_resultados = ceil($totalRows_resultados/$maxRows_resultados)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>nome</td>
<td>cpf</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_resultados['nome']; ?></td>
<td><?php echo $row_resultados['cpf']; ?></td>
</tr>
<?php } while ($row_resultados = mysql_fetch_assoc($resultados)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($resultados);
?>[/codebox]
Alguma ajuda?

Consultar Registros
Started By lomaster, 18/01/2009, 08:16
4 replies to this topic
#1
Posted 18/01/2009, 08:16
#2
Posted 18/01/2009, 08:45
mano .. blz?...
seguinte nem li todo seu codigo....
mas vou dizer para buscar resultado vc usa o LIKE E NAO =
SELECT nome, cpf FROM cadcli WHERE nome LIKE %s"
se vc usar iguallll. tera que ser exatamento igual , com o lique vc busca o contem
acho que é isso
outra coisa ... esta faltando o codigo ali da parametrização
e a variavel que coleta a infromação da busca...
cole o codigo inteiro
seguinte nem li todo seu codigo....
mas vou dizer para buscar resultado vc usa o LIKE E NAO =
SELECT nome, cpf FROM cadcli WHERE nome LIKE %s"
se vc usar iguallll. tera que ser exatamento igual , com o lique vc busca o contem
acho que é isso
outra coisa ... esta faltando o codigo ali da parametrização
e a variavel que coleta a infromação da busca...
cole o codigo inteiro
<?php $squall = new Squall(); $squall->Ajudando("você"); $resultado = $squall->solucao(); ?>
#3
Posted 18/01/2009, 18:17
ok
este é o código do busca.php
[codebox]<?php require_once('../Connections/conection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_busca = "-1";
if (isset($_GET['nome'])) {
$colname_busca = $_GET['nome'];
}
mysql_select_db($database_conection, $conection);
$query_busca = sprintf("SELECT nome, cpf FROM cadcli WHERE nome = %s", GetSQLValueString($colname_busca, "text"));
$busca = mysql_query($query_busca, $conection) or die(mysql_error());
$row_busca = mysql_fetch_assoc($busca);
$totalRows_busca = mysql_num_rows($busca);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="formulario" name="formulario" method="get" action="clientes.php">
<label></label>
<select name="buscacli" id="buscacli">
<?php
do {
?>
<option value="<?php echo $row_busca['cpf']?>"><?php echo $row_busca['cpf']?></option>
<?php
} while ($row_busca = mysql_fetch_assoc($busca));
$rows = mysql_num_rows($busca);
if($rows > 0) {
mysql_data_seek($busca, 0);
$row_busca = mysql_fetch_assoc($busca);
}
?>
</select>
<label>
<input type="submit" name="Buscar" id="Buscar" value="Submit" />
</label>
<p> </p>
</form>
</body>
</html>
<?php
mysql_free_result($busca);
?>
[/codebox]
e este é do resultado.php
[codebox]<?php require_once('../Connections/conection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_resultados = 10;
$pageNum_resultados = 0;
if (isset($_GET['pageNum_resultados'])) {
$pageNum_resultados = $_GET['pageNum_resultados'];
}
$startRow_resultados = $pageNum_resultados * $maxRows_resultados;
$colname_resultados = "-1";
if (isset($_GET['nome'])) {
$colname_resultados = $_GET['nome'];
}
mysql_select_db($database_conection, $conection);
$query_resultados = sprintf("SELECT nome, cpf FROM cadcli WHERE nome = %s", GetSQLValueString($colname_resultados, "text"));
$query_limit_resultados = sprintf("%s LIMIT %d, %d", $query_resultados, $startRow_resultados, $maxRows_resultados);
$resultados = mysql_query($query_limit_resultados, $conection) or die(mysql_error());
$row_resultados = mysql_fetch_assoc($resultados);
if (isset($_GET['totalRows_resultados'])) {
$totalRows_resultados = $_GET['totalRows_resultados'];
} else {
$all_resultados = mysql_query($query_resultados);
$totalRows_resultados = mysql_num_rows($all_resultados);
}
$totalPages_resultados = ceil($totalRows_resultados/$maxRows_resultados)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>nome</td>
<td>cpf</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_resultados['nome']; ?></td>
<td><?php echo $row_resultados['cpf']; ?></td>
</tr>
<?php } while ($row_resultados = mysql_fetch_assoc($resultados)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($resultados);
?>[/codebox]
Vlw por enquanto
este é o código do busca.php
[codebox]<?php require_once('../Connections/conection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_busca = "-1";
if (isset($_GET['nome'])) {
$colname_busca = $_GET['nome'];
}
mysql_select_db($database_conection, $conection);
$query_busca = sprintf("SELECT nome, cpf FROM cadcli WHERE nome = %s", GetSQLValueString($colname_busca, "text"));
$busca = mysql_query($query_busca, $conection) or die(mysql_error());
$row_busca = mysql_fetch_assoc($busca);
$totalRows_busca = mysql_num_rows($busca);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="formulario" name="formulario" method="get" action="clientes.php">
<label></label>
<select name="buscacli" id="buscacli">
<?php
do {
?>
<option value="<?php echo $row_busca['cpf']?>"><?php echo $row_busca['cpf']?></option>
<?php
} while ($row_busca = mysql_fetch_assoc($busca));
$rows = mysql_num_rows($busca);
if($rows > 0) {
mysql_data_seek($busca, 0);
$row_busca = mysql_fetch_assoc($busca);
}
?>
</select>
<label>
<input type="submit" name="Buscar" id="Buscar" value="Submit" />
</label>
<p> </p>
</form>
</body>
</html>
<?php
mysql_free_result($busca);
?>
[/codebox]
e este é do resultado.php
[codebox]<?php require_once('../Connections/conection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_resultados = 10;
$pageNum_resultados = 0;
if (isset($_GET['pageNum_resultados'])) {
$pageNum_resultados = $_GET['pageNum_resultados'];
}
$startRow_resultados = $pageNum_resultados * $maxRows_resultados;
$colname_resultados = "-1";
if (isset($_GET['nome'])) {
$colname_resultados = $_GET['nome'];
}
mysql_select_db($database_conection, $conection);
$query_resultados = sprintf("SELECT nome, cpf FROM cadcli WHERE nome = %s", GetSQLValueString($colname_resultados, "text"));
$query_limit_resultados = sprintf("%s LIMIT %d, %d", $query_resultados, $startRow_resultados, $maxRows_resultados);
$resultados = mysql_query($query_limit_resultados, $conection) or die(mysql_error());
$row_resultados = mysql_fetch_assoc($resultados);
if (isset($_GET['totalRows_resultados'])) {
$totalRows_resultados = $_GET['totalRows_resultados'];
} else {
$all_resultados = mysql_query($query_resultados);
$totalRows_resultados = mysql_num_rows($all_resultados);
}
$totalPages_resultados = ceil($totalRows_resultados/$maxRows_resultados)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>nome</td>
<td>cpf</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_resultados['nome']; ?></td>
<td><?php echo $row_resultados['cpf']; ?></td>
</tr>
<?php } while ($row_resultados = mysql_fetch_assoc($resultados)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($resultados);
?>[/codebox]
Vlw por enquanto
#4
Posted 19/01/2009, 08:19
o que vc eta buscado ....?
qual palavra ... por que esta acontecendo o que eu te falei.... USE O LIKE ives de =
qual palavra ... por que esta acontecendo o que eu te falei.... USE O LIKE ives de =
<?php $squall = new Squall(); $squall->Ajudando("você"); $resultado = $squall->solucao(); ?>
#5
Posted 19/01/2009, 19:24
Então...........
Concordo com sua colocação sobre o like, no entanto, estou consultando a partir de um list/menu que eu busco do banco de dados, sendo assim, não há como ser digitado algo que não exista no BD. Por isso que acho que meu problema não seja a instrução sql , mas sim a passagem de parâmetro. Desculpe pela amolação, Estou iniciando em php...........tenha paciência por favor
Concordo com sua colocação sobre o like, no entanto, estou consultando a partir de um list/menu que eu busco do banco de dados, sendo assim, não há como ser digitado algo que não exista no BD. Por isso que acho que meu problema não seja a instrução sql , mas sim a passagem de parâmetro. Desculpe pela amolação, Estou iniciando em php...........tenha paciência por favor
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)