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
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.
I wish my table with X rows, but with only 4 columns.
Sorry for my poor english.
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>