Jump to content


lomaster

Member Since 12/01/2009
Offline Last Active 15/11/2011, 22:12
-----

Posts I've Made

In Topic: Consultar Registros

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

In Topic: Consultar Registros

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>&nbsp;</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>&nbsp;</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

In Topic: Inserindo Data Em Php

15/01/2009, 21:10

inseri da seguinte maneira:

[codebox] GetSQLValueString(Convert_Data_Port_nasc($_POST['data_nasc']), "date"),
GetSQLValueString(Convert_Data_Port_instal($_POST['data_instal']), "date"), [/codebox]

e renomeei a função.

Está funcionando

abraço

In Topic: Data Não Está Sendo Inserida

15/01/2009, 20:26

Olá , colega!

O problema foi resolvido com a última dica. Só pra não deixar de encher o saco, tenho 3 campos com datas. Teria que criar 3 funções com nomes diferentes ou posso apenas trocar as $variáveis?

Valeu por enquanto!

In Topic: Inserindo Data Em Php

14/01/2009, 21:08

Colega , meu código está assim
[codebox]if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "cadastro")) {
$insertSQL = sprintf("INSERT INTO cadcli (nome, rua, num, bairro, cidade, UF, telefone, email, cep, data_nasc, data_instal, cpf, RG, id_ClienteFisico, data_Pagto, plano, banco) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['rua'], "text"),
GetSQLValueString($_POST['num'], "text"),
GetSQLValueString($_POST['bairro'], "text"),
GetSQLValueString($_POST['cidade'], "text"),
GetSQLValueString($_POST['UF'], "text"),
GetSQLValueString($_POST['telefone'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['cep'], "text"),
$data_nasc = Convert_Data_Port_Ingl($_POST['data_nasc']),
GetSQLValueString($_POST['data_instal'], "date"),
GetSQLValueString($_POST['cpf'], "text"),
GetSQLValueString($_POST['RG'], "text"),
GetSQLValueString($_POST['id_ClienteFisico'], "int"),
GetSQLValueString($_POST['data_Pagto'], "text"),
GetSQLValueString($_POST['plano'], "text"),
GetSQLValueString(isset($_POST['banco']) ? "true" : "", "defined","'Itaú'","'BB'"));



mysql_select_db($database_conection, $conection);
$Result1 = mysql_query($insertSQL, $conection) or die(mysql_error());

$insertGoTo = "sucesso.html";[/codebox]

mas o problema continua........

IPB Skin By Virteq