5 Replies - 697 Views - Last Post: 25 April 2010 - 03:37 PM

#1 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Html Tables

Posted 25 April 2010 - 12:22 PM

I am grabing info using php but my collums seems messed

http://www.pokemonto...searchy/mod.php

Here's my code

$result = mysql_query("SELECT * FROM conf") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>Title</th> <th>Url</th> <th>Description</th> <th>keywords </th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
echo "<tr><td>"; 
	echo $row['title'];
	echo "</td><td>"; 
	echo $row['url'];
echo "</tr><td>"; 
	echo $row['description'];	
	echo "</tr><td>"; 
	echo $row['keywords'];
	echo "</td></tr>"; 
} 

echo "</table>";






I don't see whats wrong like

Is This A Good Question/Topic? 0
  • +

Replies To: Html Tables

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5466
  • View blog
  • Posts: 14,421
  • Joined: 18-April 07

Re: Html Tables

Posted 25 April 2010 - 12:33 PM

Take a second look at where you are opening and closing your <td> and <tr> tags. For instance you have the line echo "</tr><td>"; but you forgot to </td> the previous cell before you closed the table row </tr>. Remember to open and close your <td> tags inside of your <tr> tags.

Also remember to include enough <td></td> pairs to match your table header cells. Just out of good habit. Even if they are empty cells.

:)

This post has been edited by Martyr2: 25 April 2010 - 12:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Html Tables

Posted 25 April 2010 - 12:47 PM

View PostMartyr2, on 25 April 2010 - 11:33 AM, said:

Take a second look at where you are opening and closing your <td> and <tr> tags. For instance you have the line echo "</tr><td>"; but you forgot to </td> the previous cell before you closed the table row </tr>. Remember to open and close your <td> tags inside of your <tr> tags.

Also remember to include enough <td></td> pairs to match your table header cells. Just out of good habit. Even if they are empty cells.

:)


i dnt get what u mean i thought i was opening and closing them
i close the preivous 1 here and open a new 1
echo "</td><td>"; 



Then i do the ecco

	echo $row['url'];




Then i close and open the next 1

echo "</tr><td>"; 


Was This Post Helpful? 0
  • +
  • -

#4 revolutionx   User is offline

  • D.I.C Head

Reputation: 60
  • View blog
  • Posts: 229
  • Joined: 23-July 09

Re: Html Tables

Posted 25 April 2010 - 02:09 PM

I've cleaned it up a little so it's easier to read, this should work.

<?php
$result = mysql_query("SELECT * FROM conf") 
or die(mysql_error());  

echo "<table border='1'>
<tr>
<th>Title</th>
<th>Url</th>
<th>Description</th>
<th>keywords</th>
</tr>";

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row into a table
	echo "<tr>";
		echo "<td>" . $row['title'] . "</td>";
        echo "<td>" . $row['url'] . "</td>";
        echo "<td>" . $row['description'] . "</td>";      
        echo "<td>" .  $row['keywords'] . "</td>";
	echo "</tr>"; 
} 

echo "</table>";



As mentioned before, the rows/columns weren't being closed properly.
Was This Post Helpful? 1
  • +
  • -

#5 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5466
  • View blog
  • Posts: 14,421
  • Joined: 18-April 07

Re: Html Tables

Posted 25 April 2010 - 02:25 PM

View Postnick1200, on 25 April 2010 - 10:47 AM, said:

View PostMartyr2, on 25 April 2010 - 11:33 AM, said:

Take a second look at where you are opening and closing your <td> and <tr> tags. For instance you have the line echo "</tr><td>"; but you forgot to </td> the previous cell before you closed the table row </tr>. Remember to open and close your <td> tags inside of your <tr> tags.

Also remember to include enough <td></td> pairs to match your table header cells. Just out of good habit. Even if they are empty cells.

:)


i dnt get what u mean i thought i was opening and closing them
i close the preivous 1 here and open a new 1
echo "</td><td>"; 



Then i do the ecco

	echo $row['url'];




Then i close and open the next 1

echo "</tr><td>"; 



You open, then echo $row['url']; but where is the </td> before you call </tr><td>? Remember you must have it like so... <tr><td></td><td></td></tr>. Notice the </td> before a </tr>. :)
Was This Post Helpful? 1
  • +
  • -

#6 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Html Tables

Posted 25 April 2010 - 03:37 PM

Thanks i get it now Thanks again
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1