Jump to content

help making tables display better from an mysql output uisng ECHO


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 ?

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.