Page 1 of 1

problem with else if

Posted: Tue Jul 06, 2010 6:07 am
by aravona
I have the following piece of code, which redirects to different pages.

The first half will send a user to a page based on if 'url_text1' is set or not. This bit works fine.

It is the Else part I need to change and everything I try just doesnt seem to want to work. Currently if the 'url_text1' is not set, then it will redirect to 1 page.

However I need it to redirect to 4 varied pages based on an ID pulled from the table.

Code: Select all

if(isset($_REQUEST['URL_Text1'])){
 		$WHEre='';
    	$SUBCat_NaMe=explode("-",$_REQUEST['URL_Text1']);
        $lastValue=$SUBCat_NaMe[sizeof($SUBCat_NaMe)-1];
        
        for($i=0;$i<sizeof($SUBCat_NaMe);$i++){
    		if($WHEre==""){
    			$WHEre=" name LIKE '".$SUBCat_NaMe[$i]."%'";
    		}else if($i==sizeof($SUBCat_NaMe)-1){
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."'";
    			//$WHEre.=" AND subcategory LIKE '%".$SUBCat_NaMe[$i]."'";
    		}else{
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."%'";
    		}
        }
        $query = "SELECT cID FROM ver_child WHERE $WHEre";
        $result_SET = $class->ResultSet($query);
        if($class->NumRows($result_SET)!=0){
        
            $_REQUEST['cmd']=2;
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['SCID']=$row_SET->cID;
            
        }
		
		else{
            $query = "SELECT prID FROM ver_pro WHERE $WHEre";
            $result_SET = $class->ResultSet($query);
            $_REQUEST['cmd']=7;
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['pr']=$row_SET->prID;
        }
        
    }
The above is the clean code. The following is my edit which so far doesn't do what I need it to.

Code: Select all

 if(isset($_REQUEST['URL_Text1'])){
 		$WHEre='';
    	$SUBCat_NaMe=explode("-",$_REQUEST['URL_Text1']);
        $lastValue=$SUBCat_NaMe[sizeof($SUBCat_NaMe)-1];
        
        for($i=0;$i<sizeof($SUBCat_NaMe);$i++){
    		if($WHEre==""){
    			$WHEre=" name LIKE '".$SUBCat_NaMe[$i]."%'";
    		}else if($i==sizeof($SUBCat_NaMe)-1){
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."'";
    			//$WHEre.=" AND subcategory LIKE '%".$SUBCat_NaMe[$i]."'";
    		}else{
    			$WHEre.=" AND name LIKE '%".$SUBCat_NaMe[$i]."%'";
    		}
        }
        $query = "SELECT cID FROM ver_child WHERE $WHEre";
        $result_SET = $class->ResultSet($query);
        if($class->NumRows($result_SET)!=0){
        
            $_REQUEST['cmd']=2;
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['SCID']=$row_SET->cID;
            
        }
		
		else{
			if ($_REQUEST['cid']=='49'){
			$_REQUEST['cmd']=9;
			}
			else {
            $query = "SELECT prID FROM ver_pro WHERE $WHEre";
            $result_SET = $class->ResultSet($query);
            $_REQUEST['cmd']=7;
            $row_SET = $class->FetchObject($result_SET);
            $_REQUEST['pr']=$row_SET->prID;
			}
        }
        
    }
The ' $_REQUEST['cid']=='49' ' refers to an ID from the table which defines a product location.

Any help would be awesome!

Thanks,

Aravona

Re: problem with else if

Posted: Wed Jul 07, 2010 2:08 am
by JakeJ
Did you try this already:

Code: Select all

if (isset($_REQUEST['cid']) && $_REQUST['cid'] =='49'){

Re: problem with else if

Posted: Wed Jul 07, 2010 3:09 am
by aravona
I'm afraid that didn't work either, its still acting like I havent asked anything.

Re: problem with else if

Posted: Wed Jul 07, 2010 3:10 am
by JakeJ
Did you echo out that variable to make sure it's even there? Perhaps it's not getting set properly.

Re: problem with else if

Posted: Thu Jul 08, 2010 2:58 am
by aravona
Yeah I got a Resource ID.

Re: problem with else if

Posted: Thu Jul 08, 2010 10:37 am
by Jade
Where are you setting your CID prior to doing the $_REQUEST? It sounds like you're not putting the right value into the CID so it's never equal to 49.