Foros del Web » Programando para Internet » PHP »

Como hacer que un campo se repita

Estas en el tema de Como hacer que un campo se repita en el foro de PHP en Foros del Web. Amigos, Tengo esta duda, tengo unos datos (libros) dentro de una bd mysql y los tengo identificados como: book_id book_category_id book_title book_description book_author Lo que ...
  #1 (permalink)  
Antiguo 20/11/2009, 10:40
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Como hacer que un campo se repita

Amigos,

Tengo esta duda, tengo unos datos (libros) dentro de una bd mysql y los tengo identificados como:

book_id
book_category_id
book_title
book_description
book_author


Lo que quiero hacer es saber cuantos libros pertenecen a una categoria y asi mismo mostrarlos. Es decir

Nombre Categoria: Categoria 1
Libros en esta categoria : Mostrar cuanto librso hay
Libros: mostrar los libros

Alguien me puede ayudar??
  #2 (permalink)  
Antiguo 20/11/2009, 10:44
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: Como hacer que un campo se repita

puedes poner un query q cuente lo de esa cateoria, algo asi:

Código php:
Ver original
  1. $bus=myql_query("SELECT *FROM tabla WHERE categoria=1");
  2. $total=mysql_num_rows($bus);
  3.  
  4. echo $total;

te arroja el numero de filas q encuntra
  #3 (permalink)  
Antiguo 20/11/2009, 10:45
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

eso lo tengo claro para que me arroje la cantidad de documentos entotrados pero lo que no se es como aumentar el campo segun la cantidad de documentos encontrados :(

Sabes como??
  #4 (permalink)  
Antiguo 20/11/2009, 10:54
Avatar de hieloverde  
Fecha de Ingreso: julio-2005
Ubicación: México, D.F
Mensajes: 467
Antigüedad: 18 años, 9 meses
Puntos: 5
Respuesta: Como hacer que un campo se repita

Cita:
Iniciado por easy Ver Mensaje
eso lo tengo claro para que me arroje la cantidad de documentos entotrados pero lo que no se es como aumentar el campo segun la cantidad de documentos encontrados :(

Sabes como??
Perdon, pero que campo quieres aumentar?
__________________
<? echo("1 <script> dice + que 1000 palabras"); ?> EspacioMéxico
  #5 (permalink)  
Antiguo 20/11/2009, 11:02
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: Como hacer que un campo se repita

no entendi nada de lo q quieres
  #6 (permalink)  
Antiguo 20/11/2009, 11:07
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

quisiera aumentar los campos de:

book_title
book_description
book_author

asi:

Titulo: Aqui el titulo
Descripcion: Aqui la descripcion
Autor: Aqui el autor

Y que esto se repita cuantas veces sea el numero sacad de mysql_num_rows, es decir si la cantidad de libros en esa categoria son 4, pues aumntar en 4 y ver los cuatro libros
  #7 (permalink)  
Antiguo 20/11/2009, 11:10
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Como hacer que un campo se repita

mm
hacer la consulta y luego desplegar los resultados con un while?
  #8 (permalink)  
Antiguo 20/11/2009, 11:15
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

es lo que pense pero no me sale
mira tengo esto:
Código PHP:
$count mysql_num_rows($book_query);
$numero $count;
$counter 1;
    while (
$counter <= $numero) {
    
$doc '<tr>
    <td height="38" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="2" height="2"></td>
        <td width="996"></td>
        <td width="2"></td>
      </tr>
      <tr>
        <td height="36"></td>
        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="498" height="36" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
              <!--DWLayoutTable-->
              <tr>
                <td width="498" height="36" valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;"><span>Documentos</span></div></td>
              </tr>
            </table>            </td>
              <td width="498" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                <!--DWLayoutTable-->
                <tr>
                  <td width="498" height="36" valign="middle" bgcolor="#FFFFFF"><div align="right" class="ptst" style="margin-right:10px;"><a href="ad.index.php?step=13&id=' 
.$rss['client_id']. '" title="Editar Documentos del Cliente ' .$rss['client_name']. '">Pulse aqu&iacute; para editar los Documentos del Cliente ' .$rss['client_name']. ' <img src="images/edit.jpg" align="absmiddle" title="Editar Documentos del Cliente ' .$rss['client_name']. '" alt="Editar Documentos del Cliente ' .$rss['client_name']. '" /></a></div></td>
                </tr>
              </table>              </td>
          </tr>
        </table></td>
        <td></td>
      </tr>
    </table></td>
  </tr>
   <tr>
    <td height="34" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="1000" height="34" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="2" height="2"></td>
              <td width="996"></td>
              <td width="2"></td>
          </tr>
          <tr>
            <td height="32"></td>
            <td valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;"><span>Libros</span></div></td>
            <td></td>
          </tr>
        </table></td>
        </tr>
    </table>    </td>
  </tr>
    <tr>
    <td height="34" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="244" height="34" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="2" height="2"></td>
            <td width="240"></td>
            <td width="2"></td>
          </tr>
          <tr>
            <td height="30"></td>
            <td valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;"><span>Titulo</span></div></td>
          <td></td>
          </tr>
          <tr>
            <td height="2"></td>
            <td></td>
            <td></td>
          </tr>
        </table>        </td>
        <td width="756" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="754" height="2"></td>
            <td width="2"></td>
          </tr>
          <tr>
            <td height="30" valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;">' 
.$book['book_title']. '</div></td>
          <td></td>
          </tr>
          <tr>
            <td height="2"></td>
            <td></td>
          </tr>
        </table>        </td>
      </tr>
    </table>    </td>
  </tr>
  <tr>
    <td height="32" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="244" height="32" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="2" height="30"></td>
            <td width="240" valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;"><span>Descripcion:</span></div></td>
          <td width="2"></td>
          </tr>
          <tr>
            <td height="2"></td>
            <td></td>
            <td></td>
          </tr>
        </table>        </td>
        <td width="756" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="754" height="30" valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;">' 
.$book['book_description']. '</div></td>
          <td width="2"></td>
          </tr>
          <tr>
            <td height="2"></td>
            <td></td>
          </tr>
        </table>        </td>
      </tr>
    </table>    </td>
  </tr>
  <tr>
    <td height="32" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="244" height="32" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="2" height="30"></td>
            <td width="240" valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;"><span>Autor:</span></div></td>
          <td width="2"></td>
          </tr>
          <tr>
            <td height="2"></td>
            <td></td>
            <td></td>
          </tr>
        </table>        </td>
        <td width="756" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="754" height="30" valign="middle" bgcolor="#FFFFFF"><div align="left" class="ptst" style="margin-left:10px;">' 
.$book['book_author']. '</div></td>
          <td width="2"></td>
          </tr>
          <tr>
            <td height="2"></td>
            <td></td>
          </tr>
        </table>        </td>
      </tr>
    </table>    </td>
  </tr>
  <tr>
    <td height="32" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="1000" height="32" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <!--DWLayoutTable-->
          <tr>
            <td width="1000" height="32">&nbsp;</td>
              </tr>
        </table></td>
        </tr>
    </table>    </td>
  </tr>'
;
    
$counter++;
    } 
  #9 (permalink)  
Antiguo 20/11/2009, 11:17
 
Fecha de Ingreso: diciembre-2007
Mensajes: 427
Antigüedad: 16 años, 4 meses
Puntos: 35
Respuesta: Como hacer que un campo se repita

while ($fila=mysql_fetch_array($bus)){
echo "titulo;".$fila['book_title']."Descripcion:".$fila[book_description]."Author:".$fila[book_author];

}

//listo puedes mostrar mejor las consultas utilizando tablas.
  #10 (permalink)  
Antiguo 20/11/2009, 11:22
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

gracias maxpwer pero me sigue saliendo solo un campo y no los 4 que tengo dentro de la tabla :P

que deberia hacer??
  #11 (permalink)  
Antiguo 20/11/2009, 11:31
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: Como hacer que un campo se repita

puede ser que pongas algo asi:
Código php:
Ver original
  1. <table>
  2. <tr><td>id</td></tr>
  3. <?php
  4. $bus=mysql_queyr("select *from tabla where campo='condicion'");
  5. $con=mysql_fetch_array($bus);
  6. do
  7. {
  8. echo '<tr>';
  9. echo '<td>'.$con['campo'].'</td>';
  10. echo '</tr>';
  11. }while($con=mysql_fetch_array($bus));
  12. ?>
  13. </table>

una idea, solo adecuala a lo q quierres
  #12 (permalink)  
Antiguo 20/11/2009, 11:33
 
Fecha de Ingreso: diciembre-2007
Mensajes: 427
Antigüedad: 16 años, 4 meses
Puntos: 35
Respuesta: Como hacer que un campo se repita

Ahy te deben salir revisa bien q con mysql_fetch_array() el te recorre la tabla de la bd y te va mostrando registro por registro.
  #13 (permalink)  
Antiguo 20/11/2009, 11:33
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Como hacer que un campo se repita

Segun el codigo que tienes, deberias colocar el mysql_fetch_array (que imagino que usas para obtener los datos de la consulta) dentro del while
  #14 (permalink)  
Antiguo 20/11/2009, 11:40
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

Nada, amigos nada de nada
hice esto:

Código PHP:
while ($book mysql_fetch_array($docquery)) {
$count mysql_num_rows($docquery);
for (
$counter 1$counter <= $count$counter++) {
$doc '';// aqui poner la estrucutra en la tabla
}

  #15 (permalink)  
Antiguo 20/11/2009, 12:29
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

ahora ya me sale pero se me repiten los campos

es decir, tengo:

book 1 (aqui me sale el libro numero uno)
book 2 (aqui me sale el libro numero uno)
book 1 (aqui me sale el libro numero dos)
book 2(aqui me sale el libro numero dos)

como hago para que me muestre

book 1 (libro 1)
book 2 (libro2)

???
  #16 (permalink)  
Antiguo 20/11/2009, 12:31
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Como hacer que un campo se repita

Deja solo el for (con mysql_fetch_array dentro) o solo el while, no los dos
  #17 (permalink)  
Antiguo 20/11/2009, 12:38
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

?? como dejo el for con mysql_dentro??, nunca lo he hecho me podrias explicar?
  #18 (permalink)  
Antiguo 20/11/2009, 12:42
Avatar de dcreate  
Fecha de Ingreso: octubre-2009
Ubicación: Veracruz
Mensajes: 536
Antigüedad: 14 años, 6 meses
Puntos: 22
Respuesta: Como hacer que un campo se repita

creo q dice q quiere q dejes algo asi:
Código php:
Ver original
  1. while ($book = mysql_fetch_array($docquery)) {
  2. $count = mysql_num_rows($docquery);
  3. $doc = '';// aqui poner la estrucutra en la tabla
  4. }

eso creo
  #19 (permalink)  
Antiguo 20/11/2009, 12:45
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Como hacer que un campo se repita

Eso, o si lo quieres hacer con el for
$count = mysql_num_rows($docquery);
for ($counter = 1; $counter <= $count; $counter++) {
$book = mysql_fetch_array($docquery);
$doc = '';// aqui poner la estrucutra en la tabla
}
  #20 (permalink)  
Antiguo 20/11/2009, 12:58
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Como hacer que un campo se repita

Gracias dark a secas, pero de esta manera no se repite el documento me toco ponerle como echo y funciona

Estoy verdaremanete muy agradecido con ustedes ya me esta funcionando

Surte en todo
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 16:35.