dynamic table in html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

dynamic table in html

Post by Nimaro »

Hy all, im printing to the screen the results of a search i make. This is the script im using...
------------------------------------------------------------------------------------------------------------------------------------------
<?php if(isset($_POST['submit'])){
$id_medico = strip_tags($_POST['id_medico']);
$exc = "SHOW TABLES"; /*VARIÁVEL RENOMEADA*/
$query = mysql_query("SELECT * FROM mensagens WHERE id_medico = '".mysql_real_escape_string($id_medico)."'");
echo "<center><font face=Verdana size=2><b>Tabelas da base de dados</b></font></center><br>";
echo "<table>";
while($dados = mysql_fetch_array($query)){
$descreva = mysql_query("SELECT * FROM mensagens WHERE id_mensagem='". $dados[0] ."'");

while($atributos = mysql_fetch_array($descreva)){
echo "<tr><td><font face=Verdana size=1>$atributos[0]</td><td><font face=Verdana size=1>| $atributos[1]</td><td><font face=Verdana size=1>| $atributos[2]</td><td><font face=Verdana size=1>| $atributos[3]</td><td><font face=Verdana size=1>| $atributos[4]</td></tr>";}
echo "</table>";
}}else{$nome = '';}
?>
----------------------------------------------------------------------------------------------------------------------------------------------
The problem is that this way is not pleasant, and im here hoping u could help me making a table in html or something like that.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: dynamic table in html

Post by papa »

Code: Select all

 
<?php 
if(isset($_POST['submit']))
{
    $id_medico = strip_tags($_POST['id_medico']);
    $exc = "SHOW TABLES"; /*VARIÁVEL RENOMEADA*/
    $query = mysql_query("SELECT * FROM mensagens WHERE id_medico = '".mysql_real_escape_string($id_medico)."'");
?>
<div id="topic">
    <b>Tabelas da base de dados</b>
</div>
<table id="content">
<?php
    while($dados = mysql_fetch_array($query)) 
    {
        $descreva = mysql_query("SELECT * FROM mensagens WHERE id_mensagem='". $dados[0] ."'");
        
        while($atributos = mysql_fetch_array($descreva)) :
?>
    <tr>
     <td><?php echo $atributos[0]; ?></td>
     <td>| <?php echo $atributos[1]; ?></td>
     <td>| <?php echo $atributos[2]; ?></td>
     <td>| <?php echo $atributos[3]; ?></td>
     <td>| <?php echo $atributos[4]; ?></td>
    </tr>
<?php endwhile; ?>
</table>
<?php
    }
} else $nome = '';
?>
An example of a cleaner code.

What you need to do next if you want to use it is to create a stylesheet for it and include it on that page.

http://www.w3schools.com/Css/default.asp
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

Re: dynamic table in html

Post by Nimaro »

ur code give a error in the last line :/
jefffan24
Forum Commoner
Posts: 72
Joined: Mon Nov 02, 2009 8:18 am

Re: dynamic table in html

Post by jefffan24 »

can you post the error it gave?
mupparion
Forum Newbie
Posts: 15
Joined: Tue Sep 22, 2009 3:48 am

Re: dynamic table in html

Post by mupparion »

try this?

Code: Select all

 
<?php
if(isset($_POST['submit']))
{
$id_medico = strip_tags($_POST['id_medico']);
$exc = "SHOW TABLES"; /*VARIÁVEL RENOMEADA*/
$query = mysql_query("SELECT * FROM mensagens WHERE id_medico = '".mysql_real_escape_string($id_medico)."'");
?>
<div id="topic">
<b>Tabelas da base de dados</b>
</div>
<table id="content">
<?php
while($dados = mysql_fetch_array($query))
{
$descreva = mysql_query("SELECT * FROM mensagens WHERE id_mensagem='". $dados[0] ."'");
while($atributos = mysql_fetch_array($descreva)) {
?>
<tr>
<td><?php echo $atributos[0]; ?></td>
<td>| <?php echo $atributos[1]; ?></td>
<td>| <?php echo $atributos[2]; ?></td>
<td>| <?php echo $atributos[3]; ?></td>
<td>| <?php echo $atributos[4]; ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php
}
} else {$nome = '';}
?>
 
Last edited by mupparion on Tue Nov 24, 2009 9:50 am, edited 2 times in total.
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

Re: dynamic table in html

Post by Nimaro »

hmmm... not now :/ ... but that was not the topic of my post.... i would just wana know how can i create a dynamic table usign php/html... dont realy know how im going to do this...
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: dynamic table in html

Post by papa »

If you don't want to post the error we can't help you.

Regarding your question, use CSS as I said in my original post.
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

Re: dynamic table in html

Post by Nimaro »

dont knwo way but i paste ur code again "papa", and it works :/... thx man

Im going to try making a table now...
User avatar
Nimaro
Forum Newbie
Posts: 19
Joined: Thu Nov 19, 2009 11:26 am

Re: dynamic table in html

Post by Nimaro »

almost there ^^....

im doing like this--->

Code: Select all

<table id="content" border="2" bordercolor="#00CC00">
 <?php
     while($dados = mysql_fetch_array($query))
     {
         $descreva = mysql_query("SELECT * FROM mensagens WHERE id_mensagem='". $dados[0] ."'");
        
         while($atributos = mysql_fetch_array($descreva)) :
 ?>
     <tr>
      <td>  <?php echo $atributos[0]; ?></td>
      <td>| <?php echo $atributos[1]; ?></td>
      <td>| <?php echo $atributos[2]; ?></td>
      <td>| <?php echo $atributos[3]; ?></td>
      <td>| <?php echo $atributos[4]; ?></td>
     </tr>
 <?php endwhile; ?>
 </table>
 <?php
     }
 } else $nome = '';
 ?>
But only first field is being puted in the table :/... u know way??
Post Reply