Jump to content

niche

Members
  • Posts

    3,671
  • Joined

  • Last visited

  • Days Won

    17

Posts posted by niche

  1. Interesting.

    When I strip-out all the white space it works:

    $stmt2->execute(array(':itemandsize' => '%' . $var . '%'));

    I've heard of white space being a problem, but haven't knowingly experienced it.

    Any thoughts?  Urban legend?

  2. This code works, but can someone tell me how I can use an array instead of bindParam in this situation. 

    try {	
    			$sql = '
    				SELECT 
    					*
    				FROM 
    					nconnectz
    				WHERE
    					itemandsize LIKE :itemandsize
    				AND 
    					price > 0	
    				ORDER BY
    					price ASC				
    			';
    			$stmt2 = $db2->prepare($sql);
    		} catch (PDOException $e) {
    			echo $e->getMessage() . '<br>';
    		}	
    				
    		$var = "%Flour%";
    		
    		try {	
    			$stmt2->bindParam(':itemandsize',$var);
    			$stmt2->execute();
    		} catch (PDOException $e) {
    			echo $e->getMessage() . '<br>';
    		}	

    Something like?

    $stmt2->execute(array(
    :itemandsize => '%Flour%' ));

     

  3. This works:
    
    $names = 
    array(
    	array("name"=>"tom","gender"=>"m"),
    	array("name"=>"jane","gender"=>"f"),
    	array("name"=>"steve","gender"=>"m"),
    	array("name"=>"mary","gender"=>"f"),
    	array("name"=>"renae","gender"=>"f")
    );	
    
    $num = 30;
    $wkvar = 'wk' . $num;
    
    foreach ($names AS $val) {
    	
    	$wk30[] = $val;
    	
    	//$$wkvar[] =  $val;
    	
    }
    
    var_dump($wk30);
    

    this doesn’t and gives me this error, “Fatal error: Cannot use [] for reading”, (goggle hasn’t helped me):

    $names = 
    array(
    	array("name"=>"tom","gender"=>"m"),
    	array("name"=>"jane","gender"=>"f"),
    	array("name"=>"steve","gender"=>"m"),
    	array("name"=>"mary","gender"=>"f"),
    	array("name"=>"renae","gender"=>"f")
    );	
    
    $num = 30;
    $wkvar = 'wk' . $num;
    
    foreach ($names AS $val) {
    	
    	//$wk30[] = $val;
    	
    	$$wkvar[] =  $val;
    	
    }
    
    var_dump($wk30);
    

    I need to use the 2nd (variable variable) approach. What am I doing wrong?

    I tried adding a dynamic index unsuccessfully.

  4. Experience tells me that If i'm thinking about restoring the registry, I'm probably going to get unexpected consequences.  So, I'll probably just reinstall the system and get a good night's sleep.

    Having the backup is one thing.  Using it is another.

     

    • Thanks 1
×
×
  • Create New...