Jump to content

help making tables display better from an mysql output uisng ECHO


CtrlAltDel

Recommended Posts

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 :)

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.

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 ...

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 ?

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 ?

Archived

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

×
×
  • 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.