..:: MX Studio Fóruns ::..: MySQL + PHP + DW consulta não retorna o resultado - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

MySQL + PHP + DW consulta não retorna o resultado

#1 User is offline   alanperes 

  • Group: Membros
  • Posts: 11
  • Joined: 28-April 04

Posted 30 April 2008 - 12:17 AM

Olá,

Estou com problema tentando fazer uma consulta ao MySQL utilizando como chave de busca o id, chave em uma tabela. O número do registro é fornecido em um formulário e o código PHP o lê e faz a consulta, só que não retorna nenhum resultado. Eu faço a mesma consulta no prompt do mysql e tudo ok. Seguem o código php (gerado pelo dreamweaver) e a tabela na qual a consulta é feita:

Código PHP

<?php require_once('../Connections/testarbd.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;
}
}

$id_rsSelect =1;
/*$id_rsSelect = $_POST['busca'];
*/echo ($id_rsSelect);
if (isset($_POST['busca'])) {
$id_rsSelect = $_POST['busca'];
}
mysql_select_db($database_testarbd, $testarbd);
$query_rsSelect = sprintf("SELECT * FROM noticia WHERE noticia.id=%s", GetSQLValueString($id_rsSelect, "int"));
$rsSelect = mysql_query($query_rsSelect, $testarbd) or die(mysql_error());
$row_rsSelect = mysql_fetch_assoc($rsSelect);
$totalRows_rsSelect = mysql_num_rows($rsSelect);

//-----------------------------------------------------
// imprimir resultado da consulta
for ($i=0; $row=mysql_fetch_row($rsSelect);$i++) {
foreach($row as $key => $value)
print ("<p> $key $value<br />");
} echo "</p>";
// ---------------------------------------------------


Tabela a ser consultada

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| data | text | NO | | | |
| destaque | varchar(255) | NO | | | |
| manchete | text | NO | | | |
| autor | varchar(255) | NO | | | |
| foto | varchar(255) | NO | | | |
| noticia | text | NO | | | |
| tipo | varchar(255) | NO | | | |
+----------+--------------+------+-----+---------+----------------+

0

#2 User is offline   alanperes 

  • Group: Membros
  • Posts: 11
  • Joined: 28-April 04

Posted 01 May 2008 - 09:19 AM

QUOTE(alanperes @ 29/4/2008 23:04:52) <{POST_SNAPBACK}>
Olá,

Estou com problema tentando fazer uma consulta ao MySQL utilizando como chave de busca o id, chave em uma tabela. O número do registro é fornecido em um formulário e o código PHP o lê e faz a consulta, só que não retorna nenhum resultado. Eu faço a mesma consulta no prompt do mysql e tudo ok. Seguem o código php (gerado pelo dreamweaver) e a tabela na qual a consulta é feita:

Código PHP

<?php require_once('../Connections/testarbd.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;
}
}

$id_rsSelect =1;
/*$id_rsSelect = $_POST['busca'];
*/echo ($id_rsSelect);
if (isset($_POST['busca'])) {
$id_rsSelect = $_POST['busca'];
}
mysql_select_db($database_testarbd, $testarbd);
$query_rsSelect = sprintf("SELECT * FROM noticia WHERE noticia.id=%s", GetSQLValueString($id_rsSelect, "int"));
$rsSelect = mysql_query($query_rsSelect, $testarbd) or die(mysql_error());
$row_rsSelect = mysql_fetch_assoc($rsSelect);
$totalRows_rsSelect = mysql_num_rows($rsSelect);

//-----------------------------------------------------
// imprimir resultado da consulta
for ($i=0; $row=mysql_fetch_row($rsSelect);$i++) {
foreach($row as $key => $value)
print ("<p> $key $value<br />");
} echo "</p>";
// ---------------------------------------------------


Tabela a ser consultada

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| data | text | NO | | | |
| destaque | varchar(255) | NO | | | |
| manchete | text | NO | | | |
| autor | varchar(255) | NO | | | |
| foto | varchar(255) | NO | | | |
| noticia | text | NO | | | |
| tipo | varchar(255) | NO | | | |
+----------+--------------+------+-----+---------+----------------+



Problema resolvido. Eu não estava entendendo como utilizar o método "mysql_fetch_assoc()" retirei-o do código e tudo funcionou como eu queria.

[]s
Alanperes
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


Similar Topics Collapse

  Topic Forum Started By Stats Last Post Info
New Replies Canadá diz que não irá regular transmissões de rádio e TV online Notícias Notícias 
  • 0 Replies
  • 235 Views
New Replies Nao consigo utilizar gradient como cor Illustrator Akn 
  • 0 Replies
  • 603 Views
New Replies IE 7 Beta 2 Preview não suporta hack Web Standards TiTi Celestino 
  • 2 Replies
  • 814 Views
New Replies parar animação
não esta dando certo
Flash & ActionScript Only Dust 
  • 11 Replies
  • 2723 Views
New Replies Ajuda com Slides
não para e exibe todos de uma só vez...
Flash & ActionScript Ictusweb 
  • 0 Replies
  • 405 Views
New Replies Jpg não abre com IE7
Qualquer navegador abre o site, só o IE7 não.
Dreamweaver Felipe Alrean 
  • 0 Replies
  • 838 Views
New Replies Publicando Dados do PHPBB
Como faço pra pegar os dados e colocar em uma pagina personalizada?
PHP Marcelo Freitas 
  • 0 Replies
  • 451 Views
New Replies Apache PHP+MySQL
como?
Outros PHPG 
  • 3 Replies
  • 1666 Views

Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)