RE: [PHP] How to show data in one row from two rows from the database

From: Date: Thu, 15 Aug 2002 14:15:50 +0000
Subject: RE: [PHP] How to show data in one row from two rows from the database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-112753@lists.php.net to get a copy of this message
[snip] Something like: $sql = "Select DISTINCT COUNTRY from tariffs"; $result=mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "Rates for {$row['COUNTRY']}<br>\n"; $sql = "select DISTINCT GROUP from tariffs where COUNTRY='{$row['COUNTRY']}' order by GROUP"; $result2=mysql_query($sql) or die(mysql_error(); while ($row2 = mysql_fetch_array($result)) { $sql = "select TIME,TARIFF from tariffs where COUNTRY='{$row['COUNTRY']}' and GROUP='{$row2['GROUP']}' order by TIME DESC"; $result3=mysql_query($sql) or die(mysql_error(); $peak ='&nbsp'; $offpeak = '&nbsp;'; while ($row3 = mysql_fetch_array($result3)) { switch (strtoupper($row3['TIME'])) { 'PEAK': $peak = $row3['TARIFF']; break; 'OFFPEAK': $offpeak = $row3['TARIFF']; break; } } echo "{$row2['GROUP']} {$row3['TIME']} {$row3['TARIFF']}<br>\n"; } } [/snip] Actually it can be handled as a CROSSTAB query in SQL without any PHP code(save for forming your tables). Have a look at this article, http://www.mysql.com/articles/wizard/index.html . HTH! Jay I’m the man of this house and I have my wife’s permission to say so *********************************************************** * Texas PHP Developers Conf Spring 2003 * * T Bar M Resort & Conference Center * * New Braunfels, Texas * * San Antonio Area PHP Developers Group * * Interested? Contact jay.blanchard@niicommunications.com * *********************************************************** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#112753) next »