Jump to content


Photo

Table help


  • Please log in to reply
5 replies to this topic

#1 lwharding

lwharding
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 01 December 2005 - 01:27 PM

I am in need to some help with my PHP & MySQL table. The below code is what I am currently using to display information from my MySQL db. However this table looks a bit of an eyesore. I want some help in making this table look a little nicer as well as adding headings for the respective fields.

For example I would like the table to look like so:

Name > Description > Price
Mr A > Mr A is a genius > £400
Mr B > Mr B is a not genius > £600
Mr C > Mr B is a not genius >£1,600


I would also like to set each results description to be a scrollable area so that I then in turn set a predefined width and length for each result.

Hope this makes sense.
Luke


echo "<table cellspacing='15'>";
echo "<tr><td colspan='4'><hr></td></tr>";
for ($i=1;$i<=sizeof($petInfo);$i++)
{
$f_price = number_format($petInfo[$i]['Price'],2);
echo "<tr>\n
<td>$i.</td>\n
<td>{$petInfo[$i]['Name']}</td>\n
<td>{$petInfo[$i]['Description']}</td>\n
<td align='right'>\$$f_price</td>\n
</tr>\n";
echo "<tr><td colspan='4'><hr></td></tr>\n";
}
echo "</table>\n";

#2 ChrisDarl

ChrisDarl
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 01 December 2005 - 01:48 PM

I don't follow what you're actually trying to do? :S

Chris

#3 lwharding

lwharding
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 02 December 2005 - 11:10 AM

Let me start again.... I want to be able to take data from the MySQL db and present this using a table of. As you will see from my original post I am using the echo table commands to display these results, which works fine. My first problem is that I want to display the results in a more aesthetically pleasing table. For example I want to create headings for each column, example in original posting. Also, to create coloured alternates for the results, E.g. result one has a background colour of blue, result two has a background colour of red, result three background colour of blue..... Because I will be displaying a description for each result I want to be able to code in a predefined scrollable area for each description. Lastly, I want to be able to set a specific height size for each result, to allow for easy viewing.

I hope this makes more sense, and apologies for my lack of definition.

Kind regards
Luke

#4 moberemk

moberemk
  • Members
  • PipPipPip
  • Advanced Member
  • 695 posts

Posted 02 December 2005 - 12:01 PM

You are in Dreamweaver, right? Then that should be really easy to do. There is also an extension for alternating row color. Just look it up!
Disclaimer: No matter how harsh I may be, I'm always IMO only.

#5 ChrisDarl

ChrisDarl
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 02 December 2005 - 02:20 PM

okay... well you can add headings simply...


<table>
  <tr>
    <td><strong>Name</strong></td>
    <td><strong>Description</strong></td>
    <td><strong>Price</strong></td>
  </tr>
  <?php
  for ($i=1;$i<=sizeof($petInfo);$i++)
  {
       $f_price = number_format($petInfo[$i]['Price'],2);
  ?>
  <tr>
    <td><?php echo {$petInfo[$i]['Name']}; ?></td>
    <td><?php echo {$petInfo[$i]['Description']}; ?></td>
    <td align="right"><?php echo $f_price; ?></td>
  </tr>
  <?php } ?>
</table>


Alternating the row colors take a look at this thread.... [a href=\"http://www.phpfreaks.com/tutorials/5/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/5/0.php[/a]

to add the description bit in a scrollable area you could just simply use a textarea like this :

<table>
  <tr>
    <td><strong>Name</strong></td>
    <td><strong>Description</strong></td>
    <td><strong>Price</strong></td>
  </tr>
  <?php
  for ($i=1;$i<=sizeof($petInfo);$i++)
  {
       $f_price = number_format($petInfo[$i]['Price'],2);
  ?>
  <tr>
    <td><?php echo {$petInfo[$i]['Name']}; ?></td>
    <td><textarea cols="" rows=""><?php echo {$petInfo[$i]['Description']}; ?></textarea></td>
    <td align="right"><?php echo $f_price; ?></td>
  </tr>
  <?php } ?>
</table>

Just set the size of the text area using cols and rows. Or use CSS to set the size of it.


Hope this is of help. Let me know if this isnt what you're after and ill see what else i can come up with.

Chris

#6 lwharding

lwharding
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 02 December 2005 - 03:16 PM

Chris, you are a genius!

Thank you so much for your patience and expertise...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users