CtrlAltDel Posted January 13, 2008 Share Posted January 13, 2008 Hello everyone, looks a good place to be for those of us not in the same league Here is my problem (well the first one) // execute the query $result= mysql_query($sql) OR die( 'QUERY ERROR:<br />' .$sql. '<br />' .mysql_error() ); ?> <table> <tr><td>Date</td><td>Title</td><td>Post</td><td>URL</td></tr> <?php while($row = MySQL_fetch_array($result)) { echo "<tr><td>{$row['formatted_date']}</td>"; echo "<td>{$row['title']}</td>"; echo "<td>{$row['post']}</td>"; echo "<td>{$row['url']}</td></tr>"; } echo "</table>"; ?> </body> </html> i wnat to recode the display on my page, so that each column has a % (date 15%, title 20%, post 40%, url 25%), with the whole table being 99% with a 1 border. I am used to html, but when i try and insert it, it gives me errors i tried this echo "<td width="25%">{$row['title']}</td>"; any clues or help on the best way to go about this please Thanks Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/ Share on other sites More sharing options...
trq Posted January 13, 2008 Share Posted January 13, 2008 The reason this.... echo "<td width="25%">{$row['title']}</td>"; generates errors is because you are ending the strings early. You need to escape the double quotes in order for them to actually display. eg; echo "<td width=\"25%\">{$row['title']}</td>"; ps: Using html like that is bad practice, you really ought to look into css. Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-437989 Share on other sites More sharing options...
Daukan Posted January 13, 2008 Share Posted January 13, 2008 This looks like the problem is you didn't escape the quotes in the html echo "<td width="25%">{$row['title']}</td>"; Should be echo "<td width=\"25%\">{$row['title']}</td>"; Edit: Oops it posted for some reason instead of giving the reply warning ... Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-437991 Share on other sites More sharing options...
CtrlAltDel Posted January 13, 2008 Author Share Posted January 13, 2008 My God, that was quick, Thanks guys I have little knowledge of ccs and wouldnt know even wheer to start I thought i did do that, but will go back and do it again and will let you know Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438005 Share on other sites More sharing options...
CtrlAltDel Posted January 13, 2008 Author Share Posted January 13, 2008 Update for you // execute the query $result= mysql_query($sql) OR die( 'QUERY ERROR:<br />' .$sql. '<br />' .mysql_error() ); ?> <table width="100%" border="1" align="center" cellpadding="2"> <tr><td>Date</td><td>Title</td><td>Post</td><td>URL</td></tr> <?php while($row = MySQL_fetch_array($result)) { echo "<tr><td width=\"25%\">{$row['formatted_date']}</td>"; echo "<td width=\"25%\">{$row['title']}</td>"; echo "<td width=\"30%\">{$row['post']}</td>"; echo "<td width=\"20%\">{$row['url']}</td></tr>"; } echo "</table>"; ?> </body> </html> I have now done this, but it doesnt seem to have taken the % for the rows. i can see the borders etc and it has also placed extra columns alongside some of then actual columns, a bit like a badly formatted table ? Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438015 Share on other sites More sharing options...
Hypnos Posted January 13, 2008 Share Posted January 13, 2008 You need to set your widths in the first row. <tr><td width="25%">Date</td><td width="25%">Title</td><td width="30%">Post</td><td width="20%">URL</td></tr> Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438023 Share on other sites More sharing options...
CtrlAltDel Posted January 13, 2008 Author Share Posted January 13, 2008 thats got it Many thanks !! Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438091 Share on other sites More sharing options...
CtrlAltDel Posted January 13, 2008 Author Share Posted January 13, 2008 Just one problem now, i dont know if this is related.. the url column has links to images in it, but they are not clickable. yet the post column also has links in and they are clickable ?? anyone know why that would be ? Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438124 Share on other sites More sharing options...
Hypnos Posted January 13, 2008 Share Posted January 13, 2008 Your code isn't applying or removing hyperlinks. It has to be how they are stored. Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438127 Share on other sites More sharing options...
CtrlAltDel Posted January 13, 2008 Author Share Posted January 13, 2008 well, they are coming from the same fields SUBSTRING(post FROM LOCATE('http://',post) FOR 70) AS url and this is the other one WHERE post LIKE '%tp:%' very strange LOL Quote Link to comment https://forums.phpfreaks.com/topic/85820-help-making-tables-display-better-from-an-mysql-output-uisng-echo/#findComment-438165 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.