Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Rafael Silvestrini

fazer include funcionar com variáveis

Recommended Posts

então, como sabemos include não abre http, eu ia utilizar iframe, mais ta ultrapassado, e tbm a página ia abrir dentro do iframe, eu precisava que ela abre estilo ao include.

 

 

meu arquivo de origem precisa receber dados para funcionar... ex: pagina.php?variaves=testando ( url não é o original e sim exemplo )

me mandaram esse codigos ( sem determina os arquivos corretos )

 

para colocar na index:

<?php
$variavel = "testando";

include("pagina.php");
?>

 

e colocar esse junto ao arquivo que o include ta redirecionado, no caso do exp. pagina.php:

<?php
echo $variavel;
//testando
?>

 

a questão e que não funcionou, e eu preciso definir isso para finalizar o site, porque as noticias queria que abrisse em categorias ja definidas, sem precisar que passe o ID para ela pegar, por isso queria ja fazer ela abrir no include com um id da categoria já definido...


qualquer coisa explico melhor... me ajudem ..



obrigado pela atenção.. acompanhe o caso pf

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você pode definir uma variável antes do include, exemplo.

 

$include = 'incluir';

 

include('pagina.php');

 

Dentro da página.php

 

if($include == 'incluir'){

//conteúdo

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

nao rola nao velho.

 

so se vc usar variavies globais ai da

 

global $include = 'incluir';



include('pagina.php');


Dentro da página.php


if($include == 'incluir'){
      //conteúdo
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Está dando erro na minha index:

Parse error: syntax error, unexpected '=', expecting ',' or ';' in /srv/disk5/930332/www/site/painel/site/index.php on line 189

 

codigo da index e esse:

<?
global $id_categoria_noticia = '3';

include('../aaa.php'); ?>

 

 

Ja definido a tabela e o ID que eu quero... podem me detalhar por favor pessoal...

Compartilhar este post


Link para o post
Compartilhar em outros sites

A linha 189 da index.php é isso?

 

<?
global $id_categoria_noticia = '3';

include('../aaa.php'); ?>

 

Tente usar o define....

 

Index.php
<?php

DEFINE(ID_CATEGORIA_NOTICIA, 3);

include('../aaa.php');

?>

Pagina.php

<?php

if(ID_CATEGORIA_NOTICIA == 3) {
   // Conteúdo
}
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

sim, a linha era do codigo mesmo, agora ele não deu erro... mais não puxou os dados... vo deixa o codigo do meu arquivo aaa.php.. quem sabe você não encontra a burrada que eu to fazendo...

Agradeço a ajuda e atenção desde já..

 

<?php require_once('Connections/rafa.php'); ?>
<?php

if(ID_CATEGORIA_NOTICIA == 3) {
   // Conteúdo
}
?>
<?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_Recordset1 = "-1";
if (isset($_GET['id_categoria_noticia'])) {
  $colname_Recordset1 = $_GET['id_categoria_noticia'];
}
mysql_select_db($database_rafa, $rafa);
$query_Recordset1 = sprintf("SELECT * FROM tbl_noticias WHERE id_categoria_noticia = %s ORDER BY id_noticia DESC", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $rafa) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset1 = "-1";
if (isset($_GET['3'])) {
  $colname_Recordset1 = $_GET['%s'];
}
?><style type="text/css">
<!--
body { margin:0px }
.style2 {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 11px;
	color: #666;
}

.style4 {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #666;
}
.style4 a:link{
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #666;
}
.style4 a:visited{
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #666;
}
.style4 a:hover{
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #000000;
}
.style3 {
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #039;
}

.style3 a:link {
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #039;
}

.style3 a:visited{
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #039;
}

.style3 a:hover{
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #000000;
}
-->
</style>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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>
<table width="498" border="0">
  <tr>
    <td width="147" height="100" rowspan="3" class="style2" ><div id="foto"><a href="ler/noticias?id=<?php echo $row_Recordset1['id_noticia']; ?>" target="_self"><img src="../imagens/noticias/<?php echo $row_Recordset1['nome_arquivo']; ?>" border="0" width="146" height="85" /></a></div></td>
    <td height="20" colspan="2"><span class="style3"><br />
          <a href="../Votuweb/noticia.php?id_noticia=<?php echo $row_Recordset1['id_noticia']; ?>"><?php echo $row_Recordset1['titulo']; ?></a></span></span> </td>
  </tr>
  <tr>
    <td width="341" height="33"><span class="style2"> <?php echo $row_Recordset1['descricao']; ?> </span></td>
  </tr>
  <tr>
    <td height="33"><div align="right"><span class="style4"> <a href="../Votuweb/noticia.php?id_noticia=<?php echo $row_Recordset1['id_noticia']; ?>">Ler Mais</a> </span></div></td>
  </tr>
</table>
</table>
</body>
</html><?php
mysql_free_result($Recordset1);
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente definir o get na index

 

Index.php

<?php
DEFINE('GET_CATEGORIA_NOTICIA', $_GET['id_categoria_noticia']);
?>

aaa.php
<?php

if(GET_CATEGORIA_NOTICIA == 3){

$stmt = "SELECT * FROM TABLE WHERE CATEGORY = ".GET_CATEGORIA_NOTICIA."";

}
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

não deu certo... da uma olhada pf na conexão msyql que vou deixar ... eu devo tar fazendo alguma cagada..

 

 

Obrigado por estar acompanhando e me ajudando.. so muito grato

 

OBS: a index não tem conexão com o banco

 

<?php require_once('Connections/rafa.php'); ?>
<?php

if(GET_CATEGORIA_NOTICIA == 3){

$stmt = "SELECT * FROM TABLE WHERE CATEGORY = ".GET_CATEGORIA_NOTICIA."";

}
?>
<?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_Recordset1 = "-1";
if (isset($_GET['id_categoria_noticia'])) {
  $colname_Recordset1 = $_GET['id_categoria_noticia'];
}
mysql_select_db($database_rafa, $rafa);
$query_Recordset1 = sprintf("SELECT * FROM tbl_noticias WHERE id_categoria_noticia = %s ORDER BY id_noticia DESC", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $rafa) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_Recordset1 = "-1";
if (isset($_GET['3'])) {
  $colname_Recordset1 = $_GET['%s'];
}
?><style type="text/css">
<!--
body { margin:0px }
.style2 {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 11px;
	color: #666;
}

.style4 {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #666;
}
.style4 a:link{
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #666;
}
.style4 a:visited{
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #666;
}
.style4 a:hover{
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 12px;
	color: #000000;
}
.style3 {
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #039;
}

.style3 a:link {
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #039;
}

.style3 a:visited{
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #039;
}

.style3 a:hover{
	font-size: 18px;
	font-family: Tahoma, Geneva, sans-serif;
	color: #000000;
}
-->
</style>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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>
<table width="498" border="0">
  <tr>
    <td width="147" height="100" rowspan="3" class="style2" ><div id="foto"><a href="ler/noticias?id=<?php echo $row_Recordset1['id_noticia']; ?>" target="_self"><img src="../imagens/noticias/<?php echo $row_Recordset1['nome_arquivo']; ?>" border="0" width="146" height="85" /></a></div></td>
    <td height="20" colspan="2"><span class="style3"><br />
          <a href="../Votuweb/noticia.php?id_noticia=<?php echo $row_Recordset1['id_noticia']; ?>"><?php echo $row_Recordset1['titulo']; ?></a></span></span> </td>
  </tr>
  <tr>
    <td width="341" height="33"><span class="style2"> <?php echo $row_Recordset1['descricao']; ?> </span></td>
  </tr>
  <tr>
    <td height="33"><div align="right"><span class="style4"> <a href="../Votuweb/noticia.php?id_noticia=<?php echo $row_Recordset1['id_noticia']; ?>">Ler Mais</a> </span></div></td>
  </tr>
</table>
</table>
</body>
</html><?php
mysql_free_result($Recordset1);
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.