toddynho
asked on
php if with url variables problem
Here's my code:
if (isset($HTTP_GET_VARS['Sub ID'])) {
$query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['C atID']."' AND SubID='".$HTTP_GET_VARS['S ubID']."'" ;
} else if (($_GET['SubID'] = '')){
$query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['C atID']."'" ;
} else {
$query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['C atID']."'" ;
}
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=some number
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"><di v id="cat"><ul>
<li><a href="javascript:wallswitc h('1');">A bstract Textures</a></li>
<li><a href="javascript:wallswitc h('2')">Tr ansportati on</a>
<?php if ( ($_GET["CatID"] == '2') ) { ?>
<input type="hidden" name="SubID" />
<ul id="subcat">
<li><a href="javascript:wallswitc h('2');jav ascript:su bswitch('1 1')">Aviat ion</a></l i>
<li><a href="javascript:wallswitc h('2');jav ascript:su bswitch('1 2')">Class ic Cars</a></li>
<li><a href="javascript:wallswitc h('2');jav ascript:su bswitch('1 3')">Hot Rods & Dragsters</a></li>
<li><a href="javascript:wallswitc h('2');jav ascript:su bswitch('1 4')">Racin g</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!
if (isset($HTTP_GET_VARS['Sub
$query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['C
} else if (($_GET['SubID'] = '')){
$query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['C
} else {
$query_rsGetWallpapers = "SELECT * FROM wallpaper_files WHERE CatID='".$HTTP_GET_VARS['C
}
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&
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.
document.wallpapers.submit
}
function subswitch ( selectedtype )
{
document.wallpapers.SubID.
document.wallpapers.submit
}
-->
</script>
then the links:
<form name="wallpapers" method="GET" action="">
<input type="hidden" name="CatID" />
<tr>
<td id="leftcolumncontent"><di
<li><a href="javascript:wallswitc
<li><a href="javascript:wallswitc
<?php if ( ($_GET["CatID"] == '2') ) { ?>
<input type="hidden" name="SubID" />
<ul id="subcat">
<li><a href="javascript:wallswitc
<li><a href="javascript:wallswitc
<li><a href="javascript:wallswitc
<li><a href="javascript:wallswitc
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You cannot remove it from the url part because you defined it as an hidden field and this should not be worse.
ASKER
thanks, that worked just fine!