problem with else if

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

problem with else if

Post 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
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: problem with else if

Post by JakeJ »

Did you try this already:

Code: Select all

if (isset($_REQUEST['cid']) && $_REQUST['cid'] =='49'){
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: problem with else if

Post by aravona »

I'm afraid that didn't work either, its still acting like I havent asked anything.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: problem with else if

Post by JakeJ »

Did you echo out that variable to make sure it's even there? Perhaps it's not getting set properly.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: problem with else if

Post by aravona »

Yeah I got a Resource ID.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: problem with else if

Post 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.
Post Reply