• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

php if with url variables problem

Here's my code:

if (isset($HTTP_GET_VARS['SubID'])) {
  $query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['CatID']."' AND SubID='".$HTTP_GET_VARS['SubID']."'";
} else if (($_GET['SubID'] = '')){
  $query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['CatID']."'";
} else {
  $query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['CatID']."'";
}

The page displays a list of available wallpapers by category and sub category.

If a main category is clicked on, the url string will be test.php?CatID=somenumber

If a sub category is clicked on, the url string will be test.php?CatID=somenumber&SubID=somenumber

This fine at first when you are clicking on the main categories; however, once you click on a sub category and then try to go back to a main category, a blank (&SubID=) is stuck in the url string in which the script then looks for a SubID match and therefore comes up with a blank set of records for the main categories.

The text links are actually form submit buttons, so, I cannot get rid of that SubID once it gets in the URL string.  Here's some more of the code so that you can see how it works:

Javascript in the head:
<script language="JavaScript" type="text/javascript">
<!--
function wallswitch ( selectedtype )
{
  document.wallpapers.CatID.value = selectedtype ;
  document.wallpapers.submit() ;
}
function subswitch ( selectedtype )
{
  document.wallpapers.SubID.value = selectedtype ;
  document.wallpapers.submit() ;
}
-->
</script>


then the links:

<form name="wallpapers" method="GET" action="">
<input type="hidden" name="CatID" />
      <tr>
                      <td id="leftcolumncontent"><div id="cat"><ul>
                          <li><a href="javascript:wallswitch('1');">Abstract Textures</a></li>
                          <li><a href="javascript:wallswitch('2')">Transportation</a>
<?php if ( ($_GET["CatID"] == '2') ) { ?>
<input type="hidden" name="SubID" />
<ul id="subcat">
<li><a href="javascript:wallswitch('2');javascript:subswitch('11')">Aviation</a></li>
<li><a href="javascript:wallswitch('2');javascript:subswitch('12')">Classic Cars</a></li>
<li><a href="javascript:wallswitch('2');javascript:subswitch('13')">Hot Rods &amp; Dragsters</a></li>
<li><a href="javascript:wallswitch('2');javascript:subswitch('14')">Racing</a></li>
</ul>
<?php } ?></li>
</td>
</tr>
</form>


The reason why I have made the text links act as for submit is because once I have this working properly I am going to have them POST to the page rather than GET in order to hide the URL variables.

Please let me know if I was unclear or if you have any questions and of course if you have a better way to do this than the round-about I am trying to do it...  Thanks!
0
toddynho
Asked:
toddynho
  • 2
1 Solution
 
danny_ebbersCommented:
if (isset($HTTP_GET_VARS['SubID']) AND ($HTTP_GET_VARS['SubID'] != '')) {
  $query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['CatID']."' AND SubID='".$HTTP_GET_VARS['SubID']."'";
} else {
  $query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['CatID']."'";
}

0
 
danny_ebbersCommented:
You cannot remove it from the url part because you defined it as an hidden field and this should not be worse.
0
 
toddynhoAuthor Commented:
thanks, that worked just fine!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now