Foros del Web » Programando para Internet » PHP »

Consulta dentro del mismo archivo php sin cambiar de pagina

Estas en el tema de Consulta dentro del mismo archivo php sin cambiar de pagina en el foro de PHP en Foros del Web. Ok. tengo tiempo con este problema.. ojala me puedan ayudar.. Bueno ahora les hablare con ejemplos y codigo http://www.elcapitolio.net/index3.php Si entras a esta url vas ...
  #1 (permalink)  
Antiguo 05/05/2008, 11:08
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Consulta dentro del mismo archivo php sin cambiar de pagina

Ok. tengo tiempo con este problema.. ojala me puedan ayudar..

Bueno ahora les hablare con ejemplos y codigo

http://www.elcapitolio.net/index3.php

Si entras a esta url vas a ver un poco lo que estoy haciendo con mi script.... ahi les aparecera el encabezado de mi noticia con titulo y un boton que dice ver nota... al dar click ahi se van a dar cuenta que si me lo muestra pero me manda a una pagina en blanco nueva. no ventana solo pagina nueva... lo que quiero hacer es que el resultado me lo muestre dentro de ese mismo cuadro de diseño donde viene mi logotipo y mis banner y eso...

les dejo el codigo de mi archivo noti.php... para que le echen un vistazo


Código PHP:
<?php require_once('Connections/noticias.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_ultimas 10
$pageNum_ultimas 0
if (isset(
$_GET['pageNum_ultimas'])) { 
  
$pageNum_ultimas $_GET['pageNum_ultimas']; 

$startRow_ultimas $pageNum_ultimas $maxRows_ultimas

mysql_select_db($database_noticias$noticias); 
$query_ultimas "SELECT * FROM noticias"
$query_limit_ultimas sprintf("%s LIMIT %d, %d"$query_ultimas$startRow_ultimas$maxRows_ultimas); 
$ultimas mysql_query($query_limit_ultimas$noticias) or die(mysql_error()); 
$row_ultimas mysql_fetch_assoc($ultimas); 

if (isset(
$_GET['totalRows_ultimas'])) { 
  
$totalRows_ultimas $_GET['totalRows_ultimas']; 
} else { 
  
$all_ultimas mysql_query($query_ultimas); 
  
$totalRows_ultimas mysql_num_rows($all_ultimas); 

$totalPages_ultimas ceil($totalRows_ultimas/$maxRows_ultimas)-1
?><!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>Documento sin t&iacute;tulo</title> 
<style type="text/css"> 
<!-- 
.bordenegro {border:1px solid black;border-bottom:1px solid black} 
.notihead {font-family: "Segoe UI", Arial; color: #000000;    font-size: 11px;} 
.notititle {font-family: "Segoe UI", Arial; color: #000000;    font-size: 11px; text-align:center; font-weight:bold} 
--> 
</style> 
</head> 

<body> 
<?php do { ?> 
<table width="100%" align="center" cellpadding="0" cellspacing="2"  onmouseover="this.style.background = '#EEEEEE';"  onmouseout="this.style.background = '#FFFFFF';" style=" border-bottom:2px solid #cccccc "> 
  <tr> 
    <td width="65%"><div class="notititle"><?php echo $row_ultimas['titulo']; ?></div> 
        <div align="center"></div></td> 
  </tr> 
  <tr> 
    <td valign="top"><div class="notihead"> 
     
    <?php echo $row_ultimas['imagen']; ?><img src="<?php echo $row_ultimas['ruta']; ?>" width="130" height="120" hspace="5" vspace="5" align="left" /> 
     --> 
     
    <?php echo $row_ultimas['resumen']; ?></div> 
</td> 
  </tr> 
  <tr> 
    <td valign="top">        <div align="right"> 
     
     
    <a href="http://www.elcapitolio.net/noticias/notas.php?pageNum_ultimas=2&amp;totalRows_ultimas=3" target="_parent"><strong><img src="/images/vernota2.gif" width="66" height="15" border="0" /></strong></a></div></td> 
  </tr> 
</table> 
<?php } while ($row_ultimas mysql_fetch_assoc($ultimas)); ?> 
<p>&nbsp;</p> 
</body> 
</html> 
<?php 
mysql_free_result
($ultimas); 
?>
Muchas gracias por su ayuda
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #2 (permalink)  
Antiguo 05/05/2008, 11:10
Avatar de pzin
Moderata 😈
 
Fecha de Ingreso: julio-2002
Ubicación: Islas Canarias
Mensajes: 10.488
Antigüedad: 21 años, 8 meses
Puntos: 2114
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Para hacer consultas a la base de datos sin recargar la página, puedes usar AJAX.

Si quieres simplemente que se muestre un recuadro, con javascript debería de bastar.

Tenemos por aquí foros de las dos cosas.
  #3 (permalink)  
Antiguo 05/05/2008, 11:19
Avatar de seik!  
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 17 años, 10 meses
Puntos: 6
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Cita:
Iniciado por Bonez Ver Mensaje
Para hacer consultas a la base de datos sin recargar la página, puedes usar AJAX.

Si quieres simplemente que se muestre un recuadro, con javascript debería de bastar.

Tenemos por aquí foros de las dos cosas.
ajax sin duda la mejor opcion... ahora si es un poko complicado para ti.. con php tbm podriar lograr algo medio makillado... talvez haciendo una segunda pagina con los mismo datos solo que muestre la noticia.. nose.. o bien en la misma... tienes q dar mas imaginacion xD


Saludos
__________________
sEIK! -Chile-
Analista Programador.
  #4 (permalink)  
Antiguo 05/05/2008, 11:22
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Cita:
Iniciado por Bonez Ver Mensaje
Para hacer consultas a la base de datos sin recargar la página, puedes usar AJAX.

Si quieres simplemente que se muestre un recuadro, con javascript debería de bastar.

Tenemos por aquí foros de las dos cosas.
En realidad no conozco nada de AJAX...

pero deja te presente sencillos ejemplos...

anteriormente utilizaba este metodo....

http://www.elcapitolio.net/index4.php

lo malo es que era muy poco configurable... si puedes da click a una nota para que veas que te la aber ahi mismo

ahora lo que desarrollo es esto.. http://www.elcapitolio.net/index3.php pero me saca del archivo php
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #5 (permalink)  
Antiguo 05/05/2008, 11:40
Avatar de seik!  
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 17 años, 10 meses
Puntos: 6
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Cita:
Iniciado por Capimaster Ver Mensaje
En realidad no conozco nada de AJAX...

pero deja te presente sencillos ejemplos...

anteriormente utilizaba este metodo....

http://www.elcapitolio.net/index4.php

lo malo es que era muy poco configurable... si puedes da click a una nota para que veas que te la aber ahi mismo

ahora lo que desarrollo es esto.. http://www.elcapitolio.net/index3.php pero me saca del archivo php
si generas un pop-up y envias la variable por javascript.. ?

ideas nomas
__________________
sEIK! -Chile-
Analista Programador.
  #6 (permalink)  
Antiguo 05/05/2008, 12:35
Avatar de pzin
Moderata 😈
 
Fecha de Ingreso: julio-2002
Ubicación: Islas Canarias
Mensajes: 10.488
Antigüedad: 21 años, 8 meses
Puntos: 2114
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Puedes hacer un include("notas.php"), y pasar una variable por index3.php, de manera que apunte a index3.php, y luego un condicional para incluir notas si se pasa un alguna variable por URL al acceder a index3.php.
  #7 (permalink)  
Antiguo 05/05/2008, 12:36
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Cita:
Iniciado por seik! Ver Mensaje
si generas un pop-up y envias la variable por javascript.. ?

ideas nomas
oye fijate que no es mala idea.... si le meto un buen diseño al popup se vera bien...

me puedes ayudar un poco mas con eso.. y explicarme un poco de como se hace
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #8 (permalink)  
Antiguo 05/05/2008, 12:55
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Cita:
Iniciado por Bonez Ver Mensaje
Puedes hacer un include("notas.php"), y pasar una variable por index3.php, de manera que apunte a index3.php, y luego un condicional para incluir notas si se pasa un alguna variable por URL al acceder a index3.php.

Esto tambien suena interesante pero como se hace? :S
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #9 (permalink)  
Antiguo 05/05/2008, 12:59
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Consulta dentro del mismo archivo php sin cambiar de pagina

Ok miren les voy a enseñar el codigo del otro script que usaba antes... para ver si me pueden explicar con esto...
es lo que quiero que haga mi nuevo script pero yo aun no lo se hacer

Código PHP:
<?

$thisurl
="http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"];
$oSystem->setValue("news_tellfriendurl",$thisurl);

/* get values */
  
$news_listno=$oSystem->getValue("news_listno");
  
$display_style=$oSystem->getValue("news_displaylayout");
  
$linkfont=$oSystem->getValue("news_linkfont");
  
$linkcolor=$oSystem->getValue("news_linkcolor");
  
$linksize=$oSystem->getValue("news_linksize");
  
$linkbold=$oSystem->getValue("news_linkbold")=="yes"1:0
  
$linkitalic=$oSystem->getValue("news_linkitalic")=="yes"1:0
  
$linkunderline=$oSystem->getValue("news_linkunderline")=="yes"1:0;
  
$textfont=$oSystem->getValue("news_textfont");
  
$textcolor=$oSystem->getValue("news_textcolor");
  
$textsize=$oSystem->getValue("news_textsize");
  
$textbold=$oSystem->getValue("news_textbold")=="yes"1:0
  
$textitalic=$oSystem->getValue("news_textitalic")=="yes"1:0
  
$textunderline=$oSystem->getValue("news_textunderline")=="yes"1:0;     
  
$displaystyle=$oSystem->getValue("news_displaylayout");



/*****Main Page*****/
if($news_id==""){    

    echo 
"<style type=\"text/css\">" .
    
" .link {font-family: $linkfont; color: $linkcolor; font-size: {$linksize}px ; font-style: " . ($linkitalic?"italic":"normal") . "; font-weight: " . ($linkbold?"bold":"normal") . "; text-decoration:" . ($linkunderline?"underline":"none") . ";}" 
    
" .text {font-family: $textfont; color: $textcolor; font-size: {$textsize}px ; font-style: " . ($textitalic"italic":"normal") . "; font-weight: " . ($textbold"bold":"normal") . "; text-decoration: " . ($textunderline?"underline":"none") . ";}" .
    
" .description {font-family: arial; color: red; font-size: 10px ; font-style: normal; font-weight: bold; text-decoration: none;} " .
    
"</style>";
    
    echo 
"<table border=0 cellspacing=5 width=98% align=center>";
    
    
$currentdate date("Y-m-d");
    
$oNews_Announce->data = array("date_format(datepost,'%d-%m-%Y') as datepost""title""summary""content""newstype""visible""dateexpire""news_id");
    
$oNews_Announce->where "newstype='news' and visible='show' and (dateexpire='0000-00-00' or dateexpire>date_format('$currentdate', '%Y-%m-%d')) and datepost<=date_format('$currentdate', '%Y-%m-%d') ";
    
$oNews_Announce->order "datepost desc, title";
    
$result $oNews_Announce->getList();
    
    if (
mysql_num_rows($result)>0){
    
        if (
$displaystyle == "1"){
            while(
$myrow=mysql_fetch_row($result)){
                echo 
"<tr><td valign=top width=15%>$myrow[0]</td><td valign=top>";
                echo 
"<div class=\"link\"><a href=\"" $_SERVER["PHP_SELF"]. "?news_id=$myrow[7]" "\" ><span class=\"link\" >$myrow[1]</span></a></div>";
                echo 
"<div class=\"text\">" stripslashes($myrow[2]) . "</div></td></tr>";
            }
        }else{
            while(
$myrow=mysql_fetch_row($result)){
                echo 
"<tr><td width=99%>";
                echo 
"<div><span class=\"link\">
<a href=\"" 
$_SERVER["PHP_SELF"]. "?news_id=$myrow[7]" "\" ><span class=\"link\">$myrow[1]</span></a></span>";
                echo 
"<span>&nbsp;&nbsp;- Publicado el <i>$myrow[0]</i></span></div><div class=\"text\">" stripslashes($myrow[2]) . " <span class=\"link\"><a href=\"" $_SERVER["PHP_SELF"]. "?news_id=$myrow[7]" "\" ><span class=\"link\">Leer más...</span></a></span><hr /></div></td></tr>";
            }
        }
        
    }else{
        echo 
"<tr><td align=center><br><br>".$lang['newsannounce']['nonewsarticlefound']."<br><br></td></tr>";
    }

    echo 
"</table><br>";

}
    
/*****News Detail*****/
if($news_id!=""){    

    
/*****Navigation Link Calculation*****/
    
$currentdate date("Y-m-d");
    
$oNews_Announce->data=array("news_id");
    
$oNews_Announce->where "visible='show' and newstype='news' and (dateexpire='0000-00-00' or dateexpire>date_format('$currentdate', '%Y-%m-%d')) and datepost<=date_format('$currentdate', '%Y-%m-%d') ";
    
$oNews_Announce->order "datepost desc, title";    $result=$oNews_Announce->getList();
    
$count=0; while($myrow=mysql_fetch_row($result)){ if($myrow[0]==$news_id){ $curpos=$count; }    $count++; }        
    
$prevpos=$curpos-1$nextpos=$curpos+1;    $curpos=$curpos+1;    $total=mysql_num_rows($result);
    if(
$prevpos>=0){ mysql_data_seek($result,$prevpos);    if($myrow=mysql_fetch_row($result)){ $previd=$myrow[0]; }}
    if(
$nextpos<$total){ mysql_data_seek($result,$nextpos); if($myrow=mysql_fetch_row($result)){ $nextid=$myrow[0]; }}        
    
mysql_free_result($result);
    
    
/*****Begin Previous and Next Navigation Link. Modify To Match Your Display*****/    
    
if($previd!=""){ $prevlink="<a href=\"".$_SERVER["PHP_SELF"]."?news_id=$previd\" style=\"text-decoration:none\"><b>".$lang['newsannounce']['prev']."</b></a>";}        
    if(
$nextid!=""){ $nextlink="<a href=\"".$_SERVER["PHP_SELF"]."?news_id=$nextid\" style=\"text-decoration:none\"><b>".$lang['newsannounce']['next']."</b></a>";}        
    if(
$prevlink!="" && $nextlink!=""){    $navline="&nbsp;&nbsp;";    }

    
$oNews_Announce->data = array("title""content""datepost");
    
$result $oNews_Announce->getDetail($news_id);
    if(
$myrow=mysql_fetch_row($result)){
        
$news_title=$myrow[0];
        
$contentHTML stripslashes($myrow[1]);
        
$posted $myrow[2];
    }
    
mysql_free_result($result);


    echo 
"<style type=\"text/css\">" .
    
" .link {font-family: $linkfont; color: $linkcolor; font-size: {$linksize}px ; font-style: " . ($linkitalic?"italic":"normal") . "; font-weight: " . ($linkbold?"bold":"normal") . "; text-decoration:" . ($linkunderline?"underline":"none") . ";}" 
    
" .text {font-family: $textfont; color: $textcolor; font-size: {$textsize}px ; font-style: " . ($textitalic"italic":"normal") . "; font-weight: " . ($textbold"bold":"normal") . "; text-decoration: " . ($textunderline?"underline":"none") . ";}" .
    
" .description {font-family: arial; color: red; font-size: 10px ; font-style: normal; font-weight: bold; text-decoration: none;} " .
    
"</style>";
    
    echo 
"
    <table border=0 cellspacing=5 width=98% align=center>
    <tr><td width=25%><a href=\""
.$_SERVER["PHP_SELF"]."\" style=\"text-decoration:none\"><b>".$lang['newsannounce']['back2list']."</b></a></td>
        <td align=center><b>"
.$lang['newsannounce']['showing']." $curpos ".$lang['newsannounce']['of']." $total</b></td>
        <td align=right width=25%>$prevlink $navline $nextlink</td>
    </tr></table>
    <hr size=1 color=#000000 width=98%>    

    <table border=0 cellspacing=5 width=98% align=center>
        <tr><td><font size=4><b>$news_title</b></font><br><i>" 
. ($posted$lang['newsannounce']['poston']." $posted":"") . "</i></td></tr>
        <tr><td><br>$contentHTML<br><br></td></tr>
    </table>
    <hr size=1 color=#000000 width=98%>    
    
    <table border=0 cellspacing=5 width=98% align=center>
        <tr><td colspan=2><table border=0 cellpadding=2 cellspacing=0><tr><td><img src=\""
.$path["webroot"]."newsannounce/image/iconprint.gif\" border=0></td><td><a href=\"javascript:printNews($news_id)\" style=\"text-decoration:none\">".$lang['newsannounce']['printerfriendly']."</a></td></tr></table></td>
        <td colspan=2><table border=0 cellpadding=2 cellspacing=0><tr><td><img src=\""
.$path["webroot"]."newsannounce/image/icontell.gif\" border=0></td><td><a href=\"javascript:tellFriend($news_id,'$url')\" style=\"text-decoration:none\">".$lang['newsannounce']['tellfriend']."</a></td></tr></table></td></tr>
    </table><br>

    "
;
}
    
?>

<script language=javascript>
function printNews(id){
    window.open("<? echo $path["webroot"?>newsannounce/home.print.php?news_id="+id,"Popup","width=550,height=450,top=70,left=100,dependent=yes,titlebar=no,scrollbars=yes,resizable=yes");    
}

function tellFriend(id,url){
    window.open("<? echo $path["webroot"?>newsannounce/home.tell.php?news_id="+id,"Popup","width=400,height=300,top=170,left=250,dependent=yes,titlebar=no,scrollbars=yes");    
}
</script>
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México

Última edición por Capimaster; 05/05/2008 a las 13:00 Razón: agregar informacion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:55.