Forum Moderators: coopster

Message Too Old, No Replies

PHP <table>-size problem

         

goran660408

6:45 pm on Sep 3, 2005 (gmt 0)


I am trying to make a PHP-guestbook for my homepage.
The only thing left is to control the width of the "messages" column in the db-table shown so that long textmessages from visitors dont dissapear in the right side of the window, but instead continues on a new line in its row in the table:

Do you have any idea how to get around this?
code(that so far has not been working for me):

<?php
include("/home/b1316/public_html/php/dbconnect.php"[smilestopper]);

$link = mysql_connect($server, $user, $password)
or die("Kunde inte an#*$!a mot databasen: " . mysql_error());

mysql_select_db($db)
or die("Kunde inte välja databasen"[smilestopper]);

// Performing SQL query
$query = 'SELECT datum,avsändare,text FROM guests ORDER BY nr DESC';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

print("<table border=1 cellpadding=2 cellspacing=2 bordercolor=000000>"[smilestopper]);
print("<tr><td width=50><b>Date</b></td><td width=50><b>From</b></td><td width=40><b>Message</b></td></tr>"[smilestopper]);

while($rad = mysql_fetch_array($result))
{
print("<tr><td>"[smilestopper]);
print($rad["datum"]);
print("</td><td>"[smilestopper]);
print($rad["avsändare"]);
print("</td><td>"[smilestopper]);
print($rad["text"]);
print("</td><tr>"[smilestopper]);

}
mysql_free_result($result);

mysql_close($link);
?>

leatherback

11:53 am on Sep 4, 2005 (gmt 0)

10+ Year Member



Hi,

The sort of thing you are trying to achieve is best done using CSS (CAscading stylesheets). Please note that using tables merely for laying out you rpages is a bit outdated. You should be using <div id="message">The message here </div> instead, and define the layout in a styesheet (See also the CCS guide, through www.w3c.org):

div#title
{
border: 1px solid #445566;
width: 250px;
margin-right: 0px;
background-color: #ffffff;
}

Link to the stylesheet IN THE HEAD section of the page:
<link REL="stylesheet" type="text/css" href="mystylehseet.css" @media="screen">

pnllan

7:06 am on Sep 5, 2005 (gmt 0)

10+ Year Member



Here's something I've done in the past:

<div align="center">
<table class="guest">
<?php do {?>
<tr>
<td>
<hr />
<br />
<p><?php echo $row_guestbook['first_name'].' '.$row_guestbook['last_name'];?><br />
<br />Location: <?php echo $row_guestbook['location'];?><br />
<br /><?php echo $row_guestbook['date'];?><br />
<br /><?php echo $row_guestbook['comments'];?></p>
</td>
</tr>

<?php } while ($row_guestbook = mysqli_fetch_assoc($guestbook));?>
</table>
</div>

It's basically the same as what you are doing except that I use a 'do-while' loop where you use a 'while' loop.

However, I take a different approach with the (X)HTML. I, personally, use valid XHTML which relies on CSS for presentation formatting. In my CSS file, I layout presentation formatting for most of my XHTML tags and create ID's or psuedo-CLASSES as necessary (NOTICE the use of the psuedo-class 'GUEST' for the TABLE that is being 'filled').

Anyway, give it a try and let me know how it works out.