Put MySql data formatted in a HTML table
| From: | A.D. Vijverberg | Date: | Tue, 09 Jan 2001 16:31:05 +0000 |
| Subject: | Put MySql data formatted in a HTML table | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-33412@lists.php.net to get a copy of this message | ||
Ls.,
For the last days I have tried to put data received from a MySql database
formatted in a HTML table without success. It is about a list of employees
of the company I work for. When I just put the data in the HTML file, the
user has to scroll to much so I want the results listed sorted in a table
with 2 columns. To make it more clear, here's an example of the preferred
layout:
<names starting with an A> <names starting with an F>
<names starting with an B> <names starting with an G>
<names starting with an C> <names starting with an H>
<names starting with an D> <names starting with an I>
<names starting with an E> <names starting with an J>
etc.
The code I tried gives me an endless loop (i guess, my browser is counting
up to 10Mb of data for 50 lines...and crashes after a while) but here it is:
if ($actie == "lyncers" && $uid == ""){
// The user wants to see all the employees...
// Print the header and retreive data from the table employee
echo "<div align='left'>";
echo "<H3>LYNC'ers</H3>";
$query = mysql_db_query($db_name, "select * from employee
WHERE active = '1' ORDER BY full_name ASC");
// The complete list is to long so divide it over 2 columns
// First find out how many results are found.
$aantal_gevonden = mysql_num_rows($query);
// To make sure the left column is always longer, add 0.3 to
$aantal_gevonden, round it and divide it by 2
$aantal_gevonden = $aantal_gevonden + 0.3;
$aantal_gevonden = round($aantal_gevonden);
$aantal_cellen = $aantal_gevonden / 2;
// Fetch the data
while($row=mysql_fetch_array($query)){
$fullname[] = $row["full_name"];
$uid[] = $row["user_id_lync"];
}
// Initialize all counters
$i = 0;
$x = 1;
$y = $aantal_cellen + 1;
// Print the table
echo "<table width='100%' border='0'>";
while ($i != $aantal_gevonden){
echo "<TR>
<TD><a
href='index.php?actie=lyncers&uid=$uid[x]'>$uid[x]</a></td>";
// Increase the counters
$x++;
$i++;
echo " <TD><a
href='index.php?actie=lyncers&uid=$uid[y]'>$uid[y]</a></td>
</TR>";
$y++;
$i++;
}
// Print a line and clear the value of $uid
echo "<BR>";
$uid = "";
}
Any help is appreciated.
Kind regards,
A.D. Vijverberg