Jump to content

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

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.