Re: Two-column display of data, second method

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

 



That was actually my primary point of optimization.  Unfortunately, I've been
feeling a bit lazy, so I didn't bother going into things. :)

Edward Dudlik
Becoming Digital
www.becomingdigital.com


----- Original Message -----
From: <Gary.Every@ingramentertainment.com>
To: <subs@becomingdigital.com>; <php-db@lists.php.net>
Sent: Friday, 20 June, 2003 10:39
Subject: RE:  Two-column display of data, second method


You could always use the % operand

<snip>
$cols_wanted = 2;
if(($faculty_found % $cols_wanted) == 0) {
// Then do a <TR>
echo '<tr>';
} else {
// Then it's the first column, and don't end the row
}
</snip>

This also simplifies it so that you can decide to use three, four or five
columns, just by changing the $cols_wanted variable




Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:gary.every@ingramentertainment.com
http://accessingram.com


> -----Original Message-----
> From: Becoming Digital [mailto:subs@becomingdigital.com]
> Sent: Thursday, June 19, 2003 5:01 PM
> To: php-db@lists.php.net
> Subject: Re:  Two-column display of data, second method
>
>
> 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
>



-- 
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