Link to home
Start Free TrialLog in
Avatar of toddynho
toddynho

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of danny_ebbers
danny_ebbers

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of danny_ebbers
danny_ebbers

You cannot remove it from the url part because you defined it as an hidden field and this should not be worse.
Avatar of toddynho

ASKER

thanks, that worked just fine!