Break rows in table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pirolilla
Forum Newbie
Posts: 13
Joined: Sat Jan 24, 2004 1:24 am

Break rows in table

Post by pirolilla »

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 in a database MySQL which begin by a letter, ordered of ascending form.

Table HTML must consist of limitless rows and 4 columns

I have all the code, unless not like inserting tags </tr><tr> each 4 rows. Please, somebody can help me?

I stick the code fragment so that it is understood well...
<?
$dbhost="localhost";
$dbusuario="***";
$dbpassword="***";
$db="genea";
$conexion = mysql_connect($dbhost, $dbusuario, $dbpassword);
mysql_select_db($db, $conexion);
?>
<?

$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.---.com/nombres.php?nombre=$row[1]'><b>$row[1]</b></a></span></td>";
}

echo"</table>";

mysql_close($conexion);
?>
In order to open to each page of each initial letter the connection it would be this:

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

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

</tr><tr>

in case that there is more than 4 results.

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.

Thanks (i speak english only a litte. Excuse me)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

search this forum for "multi column".
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

pirolilla
Forum Newbie
Posts: 13
Joined: Sat Jan 24, 2004 1:24 am

Post by pirolilla »

Thanks, I am going to watch it.
pirolilla
Forum Newbie
Posts: 13
Joined: Sat Jan 24, 2004 1:24 am

Post by pirolilla »

That code is perfect. Works Ok.

Thank you very much. :D :D :D
Post Reply