Re: Two-column display of data, second method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nice job.  There's a fair bit of room for optimization, but unless your data
sets are very large, it's probably not necessary.  However, if you're compulsive
(as I tend to be), you'll optimize every bit of code to the best of your
abilities.  And yes, I know I'm crazy. ;P

Edward Dudlik
Becoming Digital
www.becomingdigital.com


----- Original Message -----
From: "David Shugarts" <Azimuth@CompuServe.com>
To: <php-db@lists.php.net>
Sent: Thursday, 19 June, 2003 17:43
Subject:  Two-column display of data, second method


When I went looking for a script that would give me a two-column layout that
would list my faculty members in two roughly equal columns, alphabetized
down the first column and then the second, I did not find such a script.
[There was indeed a "two-column" script, but it fed the data row-by-row.]

I wrote this one and am glad to share it. The math statements could surely
be condensed, but I was using them to confirm the results. This script
either creates two equal columns if the total number of items is even, or it
makes the first column the longer if the total number of items is odd.

--Dave Shugarts


<?php

/* ******* Now selects the Faculty names ****** */

$sql ="SELECT FirstName, Middle, LastName
FROM $table_name
ORDER BY LastName, FirstName";


/* ****** Now passes the result of the search ****** */

$faculty_result = @mysql_query($sql, $connection) or die("Error #".
mysql_errno() . ": " . mysql_error());

$faculty_found = @mysql_num_rows($faculty_result);
$faculty_half = $faculty_found / 2;
$faculty_round = round($faculty_found / 2);
$faculty_remain = $faculty_found - $faculty_round;


echo "<table border=0>

<tr><td colspan=2 align=center><b>
Two-Column header
</b><br></td></tr>

<tr><td width=49%>\n";

for ($rownum = 1; $rownum <= $faculty_round; $rownum++)

{
$row = mysql_fetch_array($faculty_result);


$FirstName=$row['FirstName'];
$Middle=$row['Middle'];
$LastName=$row['LastName'];

$faculty_block = "
<font class=facultydoc>
$FirstName $Middle $LastName
</font>
<br>
";

echo "$faculty_block<br>";
}

echo "</td><td>\n";


for ($rownum = 1; $rownum <= $faculty_remain; $rownum++)

{
$row = mysql_fetch_array($faculty_result);


$FirstName=$row['FirstName'];
$Middle=$row['Middle'];
$LastName=$row['LastName'];

$faculty_block = "
<font class=facultydoc>
$FirstName $Middle $LastName
</font>
<br>
";

echo "$faculty_block<br>";
}

echo "</td></tr><br></table>";

?>


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux