Jump to content

Archived

This topic is now archived and is closed to further replies.

lwharding

Table help

Recommended Posts

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";

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.