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

From: Date: Thu, 15 Aug 2002 14:10:18 +0000
Subject: RE: [PHP] How to show data in one row from two rows from the data base
Groups: php.general 
Request: Send a blank email to php-general+get-112752@lists.php.net to get a copy of this message
> From: Ing. Rajesh Kumar [mailto:raja@netmaster.cz] > Sent: Thursday, August 15, 2002 9:36 AM > To: php-general@lists.php.net > Subject: [PHP] How to show data in one row from two rows from > the database > > > Hi everybody > What I wrote in the subject may look complicated so I added a > html file. It > explains what I have and what I want to show. > > Thanks in advance 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"; } }

« previous php.general (#112752) next »