Forum Moderators: coopster

Message Too Old, No Replies

Displaying Information in a 1 row/2 column Table

How to Do It?

         

jimh009

9:05 pm on Jul 27, 2006 (gmt 0)

10+ Year Member



Hi,

I'm very new to php scripting and haven't quite figured out what I need to do here.

I need to display information in a 1 row/2 column table. I have the MySQL query working fine, but the scripting part in php is killing me!

In the first column a graphic about 70x70 will be shown (plus some additional padding). In the second column will be the description information. The second column will be around 400 pixels wide.

How do I set this up in php? It's easy enough in HTML, but I've about killed myself trying to figure out how to properly lay this out in php!

Thanks for any help

Jim

barns101

9:25 pm on Jul 27, 2006 (gmt 0)

10+ Year Member



Something like this:


<?
mysql_connect("localhost", "user", "pass");
mysql_select_db("database");
$query = "SELECT * FROM `table`";
$result = mysql_query($query);

echo '<table>';

while ($row = mysql_fetch_array($result))
{
echo "<tr>
<td>
Content of first cell e.g. $row[field_name]
</td>
<td>
Content of second cell e.g. $row[other_field_name]
</td>
</tr>";
}
echo '</table>';
mysql_close();
?>

[edited by: barns101 at 9:27 pm (utc) on July 27, 2006]

jatar_k

9:26 pm on Jul 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I usually start with the html and then script from there.

can you show me the snippet of code that does the db query? Have you managed to successfully return the desired data from the database and store it in a variable or display it?

<added>barns is quicker ;)

jimh009

10:14 pm on Jul 27, 2006 (gmt 0)

10+ Year Member



Hi,

Thanks for the help. The SQL query is working just fine. What I'm having problem with is presenting the information ok. This is what I have so far:

while ($row = mysql_fetch_array($results)){
extract($row);
echo "<table class='mainContent'>";
echo "<tr>";
echo "<td width='80'>";
echo "<img src=$image_url width='70' height='70'";
echo "</td>";
echo "<td width='420'>";
echo "<a href=$url>$hotel_name</a>";
echo "<font class='DynamicBookDescription'> : $description</font>";
echo "</td>";
echo "</tr>";
}

-- All information is displayed - so the SQL query is working properly. Things are even laid out semi-ok. The problem is that the table that is being created is somehow completely throwin off my site layout. For whatever reason, the table seems to be punching through my fixed width layout I use. I set - or at least I thought I did, this table to be 500 pixels wide. Yet, the table seems to want to span full-width of the monitor.

Not sure why!

What am I doing wrong?

Jim

jatar_k

10:20 pm on Jul 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you need to look at the html output then

try view source abd see if that helps, or try to validate it and see if that helps

I assume you close that table somewhere

jimh009

10:22 pm on Jul 27, 2006 (gmt 0)

10+ Year Member



>> I assume you close that table somewhere

Nope! I didn't!

That was indeed the problem. PHP is so darn picky!

Thanks for all your help Jatar.

Jim

jatar_k

11:04 pm on Jul 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for layout issues, always go to view source first

then start swearing at your php later ;)