Welcome Guest, Not a member yet? Register   Sign In
table zebra problem
#1

[eluser]mattylux[/eluser]
hello

I have a problem in the construction of the table in my database,
sco
I would like to use this method but I have always an error when I insert <table class="zebraTable"> http://codeigniter.com/wiki/Zebra_Tables/


Code:
<div id="contenuto">

&lt;?php
        

  $query = $this->db->query('SELECT id, attività, insegnante, giorno, orari FROM corsi');

foreach ($query->result_array() as $row) {


echo "<table border='1'>";

      echo "<br><tr></br>";  
      echo  $row['id'];
      echo "<th><th>";  
      echo  $row['attività'];
      echo "<th>";
      echo  $row['insegnante'];
      echo "<th>";
      echo  $row['giorno'];
      echo "<td><td>";
      echo  $row['orari'];
      echo "<th></th></tr>";

echo "</table>";


}

?&gt;

</div>

</div>
only works in this way as I do? so that I can run the table zebra in my site

hello thanks
#2

[eluser]InsiteFX[/eluser]
Why not use CodeIgniters Table Class?

InsiteFX
#3

[eluser]pickupman[/eluser]
This should get you what you want. You need to place the table element outside of the foreach loop. Right now you are creating a table for each row.

Code:
<div id="contenuto">

&lt;?php
$this->load->helper('string');        

$query = $this->db->query('SELECT id, attività, insegnante, giorno, orari FROM corsi');

if( $query->num_rows() > 0 ) {
echo "<table border='1'>";

foreach ($query->result_array() as $row) {

      echo "<tr class=\"" . alternator('odd','even') . "\">";  
      echo "<td>";
      echo  $row['id'];
      echo "</td><td>";  
      echo  $row['attività'];
      echo "</td><td>";
      echo  $row['insegnante'];
      echo "</td><td>";
      echo  $row['giorno'];
      echo "</td><td>";
      echo  $row['orari'];
      echo "</td></tr>";



  }
echo "</table>";
}
?&gt;

</div>

</div>  

//CSS
tr.even, tr.even td {background: #ccc;}
#4

[eluser]Aken[/eluser]
You should be passing your data to a view and creating your HTML there, also. Separate the logic from the display, hence the reason for a MVC structure in the first place.
#5

[eluser]mattylux[/eluser]
thanks a lot I have to say that this forum is very interesting
and you can learn many things about CodeIgniter,
and if you have any interesting guide that can help me as well as wikis CodeIgniter video guide and even those I find them very interesting.




Theme © iAndrew 2016 - Forum software by © MyBB