MySQL table rows

pirolillapirolilla BeginnerLink Clerk
I am a neewbie. Recently time which I have begun to program in PHP with MySQL, and I need to solve a problem.

I have a table that relates all the registries of a table which they begin by a determined letter, ordered of ascending form. Table HTML must consist of limitless rows, of 4 columns each one. All the code unless not like inserting <tr></tr> each four <td></td>.

Please, somebody can help me? I stick the code fragment so that it is understood well...

[PHP]<?
$dbhost="localhost";
$dbusuario="***";
$dbpassword="***";
$db="genea";
$conexion = mysql_connect($dbhost, $dbusuario, $dbpassword);
mysql_select_db($db, $conexion);
?>[/PHP]

[PHP]<?

$query="SELECT * FROM nombres WHERE nombre LIKE '$letra%' ORDER BY nombre ASC";
$result=mysql_query($query, $conexion);
$num=mysql_numrows($result);

echo"<table border='0' width='100%' cellspacing='5' cellpadding='10'>";

while($row=mysql_fetch_row($result))
{
echo"<td class='row2' width='25%' align='left'><span class='topictitle'><a class='topictitle' href='http://www.dom.com/nombres.php?nombre=$row[1]'><b>$row[1]</b></a></span></td>";
}

echo"</table>";

mysql_close($conexion);
?>[/PHP]


In order to open to each page of each initial letter the connection it would be this:

http://www.dom.com/letras.php?letra=A

Comments

  • pavstapavsta Beginner Link Clerk
    *very confused* what exactly are you trying to do?
  • pirolillapirolilla Beginner Link Clerk
    OK. Language problems, i speak english only a little.

    I need the data appear in a table that has 4 columns. I always need that each four results this code is inserted:

    <tr></tr>

    in case that there is more than four results.
  • pavstapavsta Beginner Link Clerk
    so you mean for each entry in the database, and for each column it has <tr></tr> already?
  • pirolillapirolilla Beginner Link Clerk
    No, now in my script has a <td></td> for each entry in the database. But i wish that each 4 entries has </tr><tr >, so that the table only has four columns.
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    I see what you mean. At the moment, the script is putting a <td> infront of EVERY entry and a </td> behind EVERY entry. He wants the TableCell tags around every 4 entries not every single one....
  • pirolillapirolilla Beginner Link Clerk
    Well, I want the table data tag around every one, but table row each 4 entries.

    I wish my table with X rows, but with only 4 columns.

    Sorry for my poor english.
  • ForgeForge Senior Member The Royal RAM
    No problem, what I think you should check out is tutoriallized.com for something like that. If your not totally understandable with this, try doing something similiar and then try it with more knowlege. Btw, What language do you speak primarily.
    Can fat people Go skinny Dipping?
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    i think you got it wrong...

    1. you should have a <tr></tr> set for each record in the database
    2. you should have a <td></td> set for each column in each record

    so for each record in your query, you would have to either print or echo:
    1. a <tr> followed by
    2. all the <td></td>
    3. and closed with a </tr>
Sign In or Register to comment.