RE: [PHP-DB] Database Sorting by date
| From: | Rick Emery | Date: | Thu, 04 Apr 2002 15:40:36 +0000 |
| Subject: | RE: [PHP-DB] Database Sorting by date | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-18202@lists.php.net to get a copy of this message | ||
Ron,
This would indicate that $table was not set. Or that the table indicated in
$table does not exist. Print out $query; is it as you expected?
Enter the SELECT at the mysql command prompt: what is the result?
-----Original Message-----
From: Allen, Ronald L CIV [mailto:allenr@FWD.AREUR.ARMY.MIL]
Sent: Thursday, April 04, 2002 8:41 AM
To: Rick Emery
Subject: RE: [PHP-DB] Database Sorting by date
The query fails when I try to look at a month it says "Query Failed"
>Ronald L. Allen (MCSE NT, MCP, CCNA)
SR. LAN/WAN Administrator
>SFOR - Hungary, Croatia
>allenr@fwd.areur.army.mil
>ronallen@techie.com
>+36-82-500000 ext. 22580
> DSN: 760-2000
-----Original Message-----
From: Rick Emery [mailto:remery@excel.com]
Sent: Thursday, April 04, 2002 16:43
To: 'Ron Allen'; php-db@lists.php.net
Subject: RE: [PHP-DB] Database Sorting by date
Ron,
What problem are you having? I'm looking at your code, and it's so clean, I
could eat off of it. My only suggestion would be that $month will NEVER ==
"NULL". If you are testing for NULL, the test is: if ($month == NULL )
Second, $month will be assigned a value, so it will never be NULL either.
BTW, what is in drop.inc?
-----Original Message-----
From: Ron Allen [mailto:allenr@fwd.areur.army.mil]
Sent: Thursday, April 04, 2002 8:09 AM
To: php-db@lists.php.net
Subject: [PHP-DB] Database Sorting by date
Here is the problem I want to be able to view all or search through the
currency lists in the database by the month. Any help would be great!!!
Here is the code
<TABLE>
<FORM name="currency" METHOD=POST ACTION="testtest.php">
<TR HEIGHT=20><TD COLSPAN="2"><FONT SIZE="+0"
FACE="VERDANA"> <BR> <TR><TD
ALIGN=LEFT> <B>Select a CCSD:</B><BR><select name="month"
onChange="document.currency.submit()">
<option value="NULL">SELECT
<option value="NULL">VIEW ALL
<option value="2002-03">March 2002
<option value="2002-04">April 2002
<option value="2002-05">May 2002
<option value="2002-06">June 2002
<option value="2002-07">July 2002
<option value="2002-08">August 2002
<option value="2002-09">September 2002
<option value="2002-10">October 2002
<option value="2002-11">November 2002
<option value="2002-12">December 2002
</TD></tr>
</table>
<?
include '..\drop.php';
$DBName = "currency";
$table = "currency";
$db = mysql_connect("$DBhost","$DBuser","$DBpass") or
die("Problem
connecting");
mysql_select_db("$DBName") or die("Problem selecting database"); if ($month
== "NULL"){ $query = "SELECT * FROM $table"; $result = mysql_query($query)
or die ("Query failed"); //let's get the number of rows in our result so we
can use it in a for loop $numofrows = mysql_num_rows($result); } else {
$query = "SELECT * FROM $table where DATE = preg_match(Y-m,'$month')) ORDER
BY DATE"; $result = mysql_query($query) or die ("Query failed"); //let's get
the number of rows in our result so we can use it in a for loop $numofrows =
mysql_num_rows($result); }
?>
<?
echo "<TABLE BORDER=\"1\">\n";
echo "<TR
bgcolor=\"#709fff\"><TD><center><b>DATE</b></center></TD><TD><center><b>EURO
</b></center></TD><TD><center><b>EURO
RECONVERSION</b></center></TD><TD><center><b>KM</b></center></TD><TD><center
><b>KM
RECONVERSION</b></center></TD><TD><center><b>HUF</b></center></TD><TD><cente
r><b>KUNA</b></center></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#d3d3d3\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#f0f0f0\">\n";
}
echo
"<TD>".$row['DATE']."</TD><TD>".$row['EURO']."</TD><TD>".$row['EURORECON']."
</TD><TD>".$row['KM']."</TD><TD>".$row['KMRECON']."</TD><TD>".$row['HUF']."<
/TD><TD>".$row['KUNA']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php