Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] 2 TABLAS para mostrar estructura y texto

Estas en el tema de 2 TABLAS para mostrar estructura y texto en el foro de PHP en Foros del Web. Hola a todos: me explico, creé dos tablas Mysql (estructura y texto) TABLE estructura : Código: CREATE TABLE `estructura` ( `id` int(100) NOT NULL auto_increment, ...
  #1 (permalink)  
Antiguo 28/12/2014, 12:02
Avatar de BLAH !!  
Fecha de Ingreso: septiembre-2003
Ubicación: Región Metropolitana, Santiago, Chile
Mensajes: 706
Antigüedad: 20 años, 7 meses
Puntos: 16
Pregunta 2 TABLAS para mostrar estructura y texto

Hola a todos:

me explico, creé dos tablas Mysql (estructura y texto)

TABLE estructura :
Código:
CREATE TABLE `estructura` (
  `id` int(100) NOT NULL auto_increment,
  `idtxt` int(100) NOT NULL default '0',
  `img` longblob NOT NULL,
  `shape` varchar(100) collate latin1_general_ci NOT NULL default '',
  `pos` varchar(100) collate latin1_general_ci NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;
TABLE texto:
Código:
CREATE TABLE `texto` (
  `id` int(100) NOT NULL auto_increment,
  `titulo` varchar(100) collate latin1_general_ci NOT NULL default '',
  `texto` longtext collate latin1_general_ci NOT NULL,
  `attrC` varchar(10) collate latin1_general_ci NOT NULL default '',
  `attrH` int(10) NOT NULL default '0',
  `attrF` varchar(100) collate latin1_general_ci NOT NULL default '',
  `attrS` int(10) NOT NULL default '0',
  `shape` varchar(100) collate latin1_general_ci NOT NULL default '',
  `pos` varchar(100) collate latin1_general_ci NOT NULL default '',
  `lista` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;
Ambas se interconectan con los campo "pos" "shape"
y asimismo estrcutura reconoce que texto mostrar con "idtxt"

lo que quiero es lo siguiente:
el usuario tiene un panel de control en el cual puede ir creando nuevos textos en seis diferentes tipos de estructuras (a,b,c,d,e,f).

El problema lo tengo cuando quiero mostrar las estructuras creadas para cada pagina (pos : main.php, contacto.php, form.php)


Lo he creado de forma básica así:
Código PHP:
<?php
require("dbconnect.inc.php");
 
$sql   "SELECT * FROM estructura WHERE pos='main'"
 
$query mysql_query($sql) or die (mysql_error());
  While (
$row=mysql_fetch_assoc($query)){
  
$shape $row['shape'];
   if(
$shape=="a"){
      
$sqls   "SELECT * FROM texto WHERE pos='main' AND shape='$shape' ORDER BY lista ASC"
      
$querys mysql_query($sqls) or die (mysql_error());
      While (
$rows=mysql_fetch_assoc($querys)){
        
$txt="
        <TABLE width=\"850\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
         <TR>
          <TD>
          "
.$rows['titulo']."
          </TD>
         </TR>
         <TR>
          <TD>
          "
.$rows['texto']."
          </TD>
         </TR>
        </TABLE>"
;
      }
   }
   elseif(
$shape=="b"){
      
$sqls   "SELECT * FROM texto WHERE pos='main' AND shape='$shape' ORDER BY lista ASC"
      
$querys mysql_query($sqls) or die (mysql_error());
      While (
$rows=mysql_fetch_assoc($querys)){
        
$txt.="
        <TABLE width=\"850\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
         <TR>
          <TD>
          soy estructura cuando shape es b
          </TD>
                 <TD>soy estructura B</TD>
         </TR>
         <TR>
          <TD>
          "
.$rows['titulo']."
          </TD><TD></TD>
         </TR>
        </TABLE>"
;
      }
   }
// y asi para todas las estructuras diferentes.

echo "$txt";
  }
  
?>
El problema es que me esta creando una duplicidad de la estructura a
y además creo que mi código está muy engorroso.

Alguna sugerencia para leer ?

De antemano
Muchas Gracias.
__________________
Adios ...!!!!
  #2 (permalink)  
Antiguo 28/12/2014, 12:57
Avatar de BLAH !!  
Fecha de Ingreso: septiembre-2003
Ubicación: Región Metropolitana, Santiago, Chile
Mensajes: 706
Antigüedad: 20 años, 7 meses
Puntos: 16
Respuesta: 2 TABLAS para mostrar estructura y texto

disculpen ... solo question de dejar todo en una tabla y reemplazar el .= por un =
__________________
Adios ...!!!!
  #3 (permalink)  
Antiguo 28/12/2014, 13:09
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: 2 TABLAS para mostrar estructura y texto

Y por sobre todo, que lo estás posteando en el foro equivocado.
Los temas de programación so. OFF TOPIC en los foros de base de datos.

Movido a PHP.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)

Etiquetas: campo, estructura, key, mysql, select, sql, tabla, tablas
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 20:25.