Current location: Hot Scripts Forums » Programming Languages » PHP » Query problem


Query problem

Reply
  #1 (permalink)  
Old 03-09-04, 10:38 AM
Fladrif Fladrif is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Query problem

The following script works great, except it will only display odd years (i.e. 1991, 1993, and so on). If I select an even year from the drop down menu I get nothing, no error message or data. Any idea why this would happen.



****Drop Down Menu****

<FORM NAME="form" action="year.php" method="get">
<SELECT NAME="site" size=1 onChange="javascript:jumpBox()">
<OPTION VALUE="">Class of.....
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1980">1980
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1981">1981
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1982">1982
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1983">1983
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1984">1984
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1985">1985
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1986">1986
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1987">1987
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1988">1988
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1989">1989
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1990">1990
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1991">1991
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1992">1992
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1993">1993
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1994">1994
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1995">1995
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1996">1996
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1997">1997
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1998">1998
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=1999">1999
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=2000">2000
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=2001">2001
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=2002">2002
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=2004">2003
<OPTION VALUE="http://www.mysite.com/index.php?s=alumni-database&year=2004">2004

</SELECT>
</FORM>





***script***
<?php

//Log on to Database
$host = "localhost";
$user = "username";
$pass = "pass";
$dbname = "db name";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
//query for data from class field
$year = $_GET['year'];
$result = mysql_query("SELECT * FROM address WHERE Class='$year'");

if ($header = mysql_fetch_array($result)) {
//create table
echo "<table align=center border=0 cellpadding=0 cellspacing=0>\n";


printf( "<tr><td align=center><strong>%s</strong><hr></td></tr>\n", $header["Class"]);

do {
//write data from class field to new table
printf("<tr><td align=center><br>%s %s</td></tr>\n", $header["First"], $header["Last"]);

} while ($header = mysql_fetch_array($result));


//if there is no data in the db user will get this error
} else {



printf( "Sorry, no one from<strong> $year </strong>has registered in the alumni database\n", $header["Class"]);
echo "</table>\n";
}
?>
********
Reply With Quote
  #2 (permalink)  
Old 03-09-04, 01:13 PM
Fladrif Fladrif is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Never mind I figured it out, wasn't a problem with the query it was with my include statement...


Was:
<?
if($year == "")
include("year-select.php");


if($s == "alumni-database" & $_GET['year'])
include("year.php");
?>

Changed it to:

<?
if($year == "")
include("year-select.php");


if($s == "alumni-database")
include("year.php");
?>


For some reason the $_GET['year'] was messing it up.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
Problem Dealing with Null Valuers in SQL Query hai_anilreddy Visual Basic 3 02-08-04 08:39 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
ASP SQL query string problem CollinAmes ASP 2 10-24-03 11:09 AM


All times are GMT -5. The time now is 09:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.