inserting php into a table

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

inserting php into a table

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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>';
}
?>
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

so theres no <table> ? just </table> ?

How do i allow that for customization via css if its just </table>
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

and table doesnt appear...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply