Ver Mensaje Individual
  #9 (permalink)  
Antiguo 08/03/2010, 10:45
Avatar de HiToGoRoShi
HiToGoRoShi
 
Fecha de Ingreso: abril-2008
Mensajes: 849
Antigüedad: 16 años
Puntos: 31
Respuesta: Hacer conexiones a dos DB ?

ok, este es mi script INDEX.PHP donde se carga la DB...

Código PHP:
Ver original
  1. <?php
  2. //Conexiones a mis dos DB
  3. include_once("../db/foro.php");
  4. $link = Conectarse();
  5. include_once("../db/portal.php");
  6. $cnPortal = Portal();
  7. //Inclur los prefijos
  8. include_once("../sql/tables.php");
  9. ?>
  10. <link href="css/style.css" rel="stylesheet" type="text/css" />
  11. <table width="100%">
  12.   <tr>
  13.     <td colspan="5">Bienvenido al Panel de Control para el Portal</td>
  14.   </tr>
  15.   <tr>
  16.     <td width="7%">Noticias</td>
  17.     <td width="33%">Anuncios</td>
  18.     <td width="20%">&nbsp;</td>
  19.     <td width="20%">&nbsp;</td>
  20.     <td width="20%">&nbsp;</td>
  21.   </tr>
  22.   <tr>
  23.     <td colspan="5"><p>
  24.       <?php include_once("noticia/noticias.php")?>
  25.     </td>
  26.   </tr>
  27. </table>

Y este es el apartado de NOTICIAS

Código PHP:
Ver original
  1. <?php
  2. //Script para evitar que no se realize nada sin haber presionado previamente el botoncito del mal.. jijiiji
  3. if ($_GET['action'] == "true"){
  4.  
  5. }
  6. ?>
  7. <form method="GET" action="index.php">
  8. <fieldset><legend>Acciones:</legend>
  9.   <table width="100%">
  10.     <tr>
  11.       <td width="29%"><input type="radio" name="noticia" value="modificar" />
  12.       Modificar Noticia</td>
  13.       <td width="27%"><input type="radio" name="noticia" value="eliminar" />
  14.         Eliminar Noticia
  15. </td>
  16.       <td width="39%"><input type="radio" name="noticia" value="crear" />
  17.       Crear nueva noticia        </td>
  18.     <td width="5%" align="center"><input type="submit" name="btn" id="btn" value="Enviar" /></td>
  19.   </tr>
  20. </table>
  21. </fieldset>
  22. </form>
  23. <?php
  24. if ($_GET['noticia']=="modificar"){
  25. ?>
  26. <form method="GET" action="index.php">
  27. <fieldset><legend>Modificar Noticia:</legend>
  28.   <table width="100%">
  29.     <tr>
  30.       <td width="6%">Noticia:</td>
  31.       <td width="89%"><select name="noticia" id="noticia">
  32.  
  33. <?php
  34. //traer las noticias ya existentes carajo !!
  35. $nt = mysql_query ("select * from $tabla[2]",$cnPortal) or die(mysql_error());
  36. //Imprimir el combolist
  37. while($noticias = mysql_fetch_array($nt)){
  38.     print "<option value=".$noticias['id']." >".$noticias['titulo']."</option>";
  39. }
  40. ?>
  41.       </select></td>
  42.     <td width="5%" align="center"><input type="submit" name="btn" id="btn" value="Enviar" /></td>
  43.   </tr>
  44. </table>
  45. </fieldset>
  46. </form>
  47. <?php  
  48. }
  49. ?>
  50.  
  51. <?php
  52. if ($_GET['noticia']=="eliminar"){
  53. ?>
  54. <form method="GET" action="index.php">
  55. <fieldset>
  56.   <legend>Eliminar:</legend>
  57.   <table width="100%">
  58.     <tr>
  59.       <td width="6%">Noticia:</td>
  60.       <td width="89%"><select name="noticia" id="noticia">
  61.  
  62. <?php
  63. //traer las noticias ya existentes carajo !!
  64. $nt = mysql_query ("select * from $tabla[2]",$cnPortal) or die(mysql_error());
  65. //Imprimir el combolist
  66. while($noticias = mysql_fetch_array($nt)){
  67.     print "<option value=".$noticias['id']." >".$noticias['titulo']."</option>";
  68. }
  69. ?>
  70.       </select></td>
  71.     <td width="5%" align="center"><input type="submit" name="btn" id="btn" value="Enviar" /></td>
  72.   </tr>
  73. </table>
  74. </fieldset>
  75. </form>
  76. <?php  
  77. }
  78. ?>
  79.  
  80. <?php
  81. if($_GET['noticia']=="crear"){
  82.     ?>
  83. <form method="GET" action="index.php">
  84. <fieldset>
  85.   <legend>Generar Noticia:</legend>
  86.   <table width="100%">
  87.     <tr>
  88.       <td width="46%"><input type="radio" name="noticia" value="nueva" />
  89.       Noticia Nueva</td>
  90.       <td width="49%"><input type="radio" name="noticia" value="phpbb" />
  91. Noticia extraida del phpBB3
  92.   <input type="hidden" name="action" id="actioon" value="true" /></td>
  93.     <td width="5%" align="center"><input type="submit" name="btn" id="btn" value="Enviar" /></td>
  94.   </tr>
  95. </table>
  96. </fieldset>
  97. </form>
  98. <?php
  99. }
  100. ?>
  101.  
  102. <?php
  103. //Si se elegio NUEVA NOTICIA
  104. if ($_GET['noticia'] == "nueva"){
  105. ?>
  106.  
  107. <form action="" method="GET" enctype="multipart/form-data" name="form1" id="form1">
  108. <fieldset>
  109.   <legend>Generando una nueva noticia:</legend>
  110.  
  111.   <table width="100%">
  112.     <tr>
  113.       <td width="10%"> Elija la Categoria:     </td>
  114.       <td width="85%">
  115.         <select name="categoria" id="categoria">
  116.           <option value="analisis">Analisis</option>
  117.           <option value="entrevista">Entrevistas</option>
  118.           <option value="novedad">Novedades</option>
  119.           <option value="concierto">Conciertos</option>
  120.         </select>
  121.       </td>
  122.       <td width="5%" align="center">&nbsp;</td>
  123.     </tr>
  124.     <tr>
  125.       <td>Titulo:</td>
  126.       <td><input name="titulo" type="text" id="titulo" size="50" maxlength="50" /></td>
  127.       <td align="center">&nbsp;</td>
  128.     </tr>
  129.     <tr>
  130.       <td valign="top">Contenido:</td>
  131.       <td><textarea name="comentario" cols="100" rows="10" id="comentario"></textarea></td>
  132.       <td align="center">&nbsp;</td>
  133.     </tr>
  134.     <tr>
  135.       <td valign="top">Imagen:</td>
  136.       <td><input type="file" name="img" id="img" />
  137.         <input type="hidden" name="action" id="actioon2" value="NoticiaNueva" />
  138.         <input type="hidden" name="noticia" id="actioon3" value="nueva" /></td>
  139.       <td align="center"><input type="submit" name="btn" id="btn" value="Enviar" /></td>
  140.     </tr>
  141.   </table>
  142. </fieldset>
  143. </form>
  144. <?php
  145. }
  146. //Si se elegio extraerla del FORO
  147. if ($_GET['noticia'] == "phpbb"){
  148. ?>
  149. <form id="form2" name="form1" method="GET" action="">
  150.   <fieldset>
  151.     <legend>Extrayendo una noticia del foro: </legend>
  152.     <table width="100%">
  153.       <tr>
  154.         <td width="10%"> Elija la Categoria: </td>
  155.         <td width="85%">
  156.         <select name="categoria" id="categoria">
  157.           <option value="analisis">Analisis</option>
  158.           <option value="entrevista">Entrevistas</option>
  159.           <option value="novedad">Novedades</option>
  160.           <option value="concierto">Conciertos</option>
  161.         </select></td>
  162.         <td width="5%" align="center">&nbsp;</td>
  163.       </tr>
  164.       <tr>
  165.         <td>Escriba el ID:</td>
  166.         <td><input name="foroID" type="text" id="foroID" size="10" maxlength="10" /></td>
  167.         <td align="center">&nbsp;</td>
  168.       </tr>
  169.       <tr>
  170.         <td>Imagen:</td>
  171.         <td><input type="file" name="img" id="img" />
  172.         <input type="hidden" name="action" id="actioon4" value="NoticiaPHPbb" />
  173.         <input type="hidden" name="noticia" id="actioon5" value="phpbb" /></td>
  174.         <td align="center"><input type="submit" name="btn" id="btn" value="Enviar" /></td>
  175.       </tr>
  176.     </table>
  177.   </fieldset>
  178. </form>
  179. <p>
  180.   <?php
  181. }
  182. //Almacenando las nuevas noticias generadas
  183. if($_GET['action']=="NoticiaNueva"){
  184.    
  185.     //Validando que no haya campos en blancos
  186.     if($_GET['categoria']==""){
  187.         print "<table width=100% class=advertencia><tr><td>No puede dejar campos en blancos, vuelva a intentarlo</td></tr></table>";
  188.         $_GET['noticia'] = "nueva";
  189.     }//Si todo esta bien procesamos la noticia CARAJO
  190.     else{
  191.     $categoria = $_GET['categoria'];
  192.     $titulo = $_GET['titulo'];
  193.     $comentario = $_GET['comentario'];
  194.     $img = $_GET['img'];
  195.     $fecha = date("d/m/Y");
  196.    
  197.     mysql_query("insert into $tabla[2] (titulo,comentario,img,categoria,fecha) values ('$titulo','$comentario','$img','$categoria','$fecha')",$cnPortal) or die(mysql_error());
  198.     print "<table width=100% class=satisfactorio><tr><td>Noticia publicada correctamente !!</td></tr></table>";
  199.     }  
  200.    
  201. }
  202.  
  203. //Almacenando las noticias de las ya existentes del PHPBb
  204. if($_GET['action']=="NoticiaPHPbb"){
  205.    
  206.     //Validando que no haya campos en blancos
  207.     if($_GET['foroID']==""){
  208.         print "<table width=100% class=advertencia><tr><td>No puede dejar campos en blancos, vuelva a intentarlo</td></tr></table>";
  209.         $_GET['noticia'] = "nueva";
  210.     }//Si todo esta bien procesamos la noticia CARAJO
  211.     else{
  212.     $categoria = $_GET['categoria'];
  213.     $foroID = $_GET['foroID'];
  214.     $img = $_GET['img'];
  215.     $fecha = date("d/m/Y");
  216.    
  217.     $extraer = mysql_query("select topic_first_poster_name,topic_title,post_text from $tabla[1] inner join phpbb_posts on phpbb_topics.topic_id = phpbb_posts.topic_id where topic_id='$foroID'",$link) or die(mysql_error());
  218.     $topic = mysql_fetch_array($extraer);
  219.    
  220.     //Almacenando los datos del FORO
  221.     $titulo = $topic['topic_title'];
  222.     $autor = $topic['topic_first_poster_name'];
  223.     $comentario = $topic['post_text'];
  224.    
  225.     print $titulo." ".$autor." ".$comentario;
  226.    
  227.         mysql_query("insert into $tabla[2] (titulo,comentario,img,categoria,fecha) values ('$titulo','$comentario','$img','$categoria','$fecha')",$cnPortal) or die(mysql_error());
  228.    
  229.     print "<table width=100% class=satisfactorio><tr><td>Noticia substraida correctamente !!</td></tr></table>";
  230.     }  
  231.    
  232. }
  233. ?>