Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL Parameter with hyphen 1

Status
Not open for further replies.

jsteiner87

Programmer
Oct 9, 2003
76
US
I am working on a sports page for a high school and I have the schedules setup so they can archive old ones. The only problems is when I pass a URL parameter like the following:
somePHPpage.php?year=2004-2005
It will not give me the schedule 2004-2005 but when I use:
somePHPpage.php?year=2005
it will give me the 2005 schedule.
I have in the database a column for the year and when you enter in a data it get entered in as 2005 or 2004-2005. Is the hyphen causing this problem?
 
Did you try escaping it? Like

Code:
somePHPpage.php?year=2004%2D2005

It is possible that it does not allow symbols in the url without doing the above.
 
try what danomac suggested.

your parmeter year=2004-2005 is more than likely being calculated year=(2004-2005) aka -1

but i'm wondering how you are storing in your year table.
are your listing like:
2003
2004
2005, etc or do you have listings with 2004-2005

if not you'll have to do a little coding to search where year >= 2004 and year <= 2005 ..

or in other words try using
where year BETWEEN 2004 and 2005
 
That didn't work.
In my database I am storing a sport that takes place in 2005 as 2005 in the year column. And if the sport spans over 2 years, for example 2004-2005, it then has 2004-2005 in the column.

Example of the Year column in the table
|Sport |Year |
|Football |2005 |
|Basketball|2004-2005|

The can you not have a hyphen in the URL parameter? Because like I said before, it works if you have a sport with just "2005".
 
It depends what your year column's format is, if it is varchar, or if it is INT. if it is a varchar the comparison coding for the sql statement, would require a modification. instead of "where year = $value" it would be something like
where year LIKE "%$value%" so it compares a string as oposed to a number. becaue if not what you are comparing is indeed 2004 minus 2005 or -1 as Bitfuzzy said.
 
In the database it is setup as a VARCHAR and here is my SQL code:
Code:
$colname_rsSchedule = "1";
if (isset($HTTP_GET_VARS['sportID'])) {
  $colname_rsSchedule = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['sportID'] : addslashes($HTTP_GET_VARS['sportID']);
}
$colname_rsYear = "1";
if (isset($HTTP_GET_VARS['year'])) {
  $colname_rsYear = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['year'] : addslashes($HTTP_GET_VARS['year']);
}
mysql_select_db($database_bluffton, $bluffton);
$query_rsSchedule = sprintf("SELECT * FROM schedule WHERE sportID = %s AND year = %s ORDER BY `date` ASC", $colname_rsSchedule, $colname_rsYear);
$rsSchedule = mysql_query($query_rsSchedule, $bluffton) or die(mysql_error());
$row_rsSchedule = mysql_fetch_assoc($rsSchedule);
$totalRows_rsSchedule = mysql_num_rows($rsSchedule);
 
A few things jump out from your code.

You should be using the superarray $_GET instead of $HTTP_GET_VARS which is depreciated and may disappear.

When you create your query, you need to surround all text values with single quotes:
Code:
$query_rsSchedule = sprintf("SELECT * FROM schedule WHERE sportID = [red]'[/red]%s[red]'[/red] AND year = [red]'[/red]%s[red]'[/red] ORDER BY `date` ASC", $colname_rsSchedule, $colname_rsYear);
But why use sprintf when a simple string assignment will work fine:
Code:
$query_rsSchedule = "SELECT * FROM schedule WHERE sportID = '$colname_rsSchedule' AND year = '$colname_rsYear' ORDER BY `date` ASC";
Also whenever I use "or die()" on a mysql function, I always print the contents of the query as well as the mysql_error(). It's a good way of finding problems.

Ken
 
I forgot something that simple, DANG!

I have the query like that because I did it in Dreamweaver and that is what the wizard gave me. When I hande code a SQL string I do it how you have it on the bottom.

Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top