lwharding Posted December 1, 2005 Share Posted December 1, 2005 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"; Quote Link to comment Share on other sites More sharing options...
ChrisDarl Posted December 1, 2005 Share Posted December 1, 2005 I don't follow what you're actually trying to do? :S Chris Quote Link to comment Share on other sites More sharing options...
lwharding Posted December 2, 2005 Author Share Posted December 2, 2005 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 Quote Link to comment Share on other sites More sharing options...
moberemk Posted December 2, 2005 Share Posted December 2, 2005 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! Quote Link to comment Share on other sites More sharing options...
ChrisDarl Posted December 2, 2005 Share Posted December 2, 2005 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 Quote Link to comment Share on other sites More sharing options...
lwharding Posted December 2, 2005 Author Share Posted December 2, 2005 Chris, you are a genius! Thank you so much for your patience and expertise... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.