Page 1 of 1

inserting php into a table

Posted: Thu Jul 13, 2006 6:11 pm
by blade_922
My php code

Code: Select all

<?php

$self = 'http://www.mysite.com/';

$content=mysql_query("select * from mos_content ORDER BY `id` DESC LIMIT 5") or die(mysql_error());
while ($donnee = mysql_fetch_array($content))

{ 

$title =  $donnee['title'];
echo "</table><tr><a href='$self/latestnews/$title'>$title</a></tr></br>";

  }

?>

K i want to insert all that into a neat table so that i can customize table bg border width etc. i have no idea how to do it coz of the loop.

Posted: Thu Jul 13, 2006 6:14 pm
by RobertGonzalez

Code: Select all

<?php
$self = 'http://www.mysite.com/';

$content=mysql_query("select * from mos_content ORDER BY `id` DESC LIMIT 5") or die(mysql_error());
while ($donnee = mysql_fetch_array($content))
{
    $title =  $donnee['title'];
    echo '</table><tr><a href="' . $self . '/latestnews/' . $title . '">' . $title .'</a></tr></br>';
}
?>

Posted: Thu Jul 13, 2006 6:23 pm
by blade_922
so theres no <table> ? just </table> ?

How do i allow that for customization via css if its just </table>

Posted: Thu Jul 13, 2006 8:16 pm
by blade_922
and table doesnt appear...

Posted: Thu Jul 13, 2006 8:58 pm
by Benjamin
Untested..

Code: Select all


table.thisClass {
  border-width: 0px 0px 1px 1px;
  border-style: solid;
  border-color: #000000;
}

td.thisClass {
  border-width: 1px 1px 0px 0px;
  border-style: solid;
  border-color: #000000;
  padding: 5px;
}

Code: Select all

<table cellpadding="0" cellspacing="0" border="0" class="thisClass">
<?php
$self = 'http://www.mysite.com/';

$content=mysql_query("select `title` from `mos_content` ORDER BY `id` DESC LIMIT 5") or die(mysql_error());
while ($donnee = mysql_fetch_array($content))
{
    echo "<tr>\n";
    echo '  <td class="thisClass"><a href="' . $self . '/latestnews/' . $donnee['title'] . '">' . $donnee['title'] .'</a></td>' . "\n";
    echo "</tr>\n";
}
?>
</table>

Posted: Thu Jul 13, 2006 10:27 pm
by RobertGonzalez
I think I should have read the original post better. Sorry for my crappy post earlier.

Astions has the ticket. Basically, open the table, then run the while loop adding in your rows and cells within the while loop. After you close the loop, close the table.