Can any1 tell me what is wrong with this PHP code?

Discussion in 'Programming' started by Mr. Pimp, Dec 20, 2009.

  1. #1
    Hello
    Can any1 tell me what is wrong with following code :

    $row= null;
    $dupconp = array();
    $dupconb = array();
    $dupcone = array();
    $dupcona = array();
    $dupconr = array();
    $qrxyz = mysql_query("SELECT * FROM example");
    while ($spdt = mysql_fetch_array($qrxyz))
    {
    	if($spdt['status']=="statusa")
    		array_push($dupconp, $spdt['email']);
    	
    	else if($spdt['status']=="statusb")
    		array_push($dupconb, $spdt['email']);
    	
    	else if($spdt['status']=="statusc")
    		array_push($dupcone, $spdt['email']);
    	
    	else if($spdt['status']=="statusd")
    		array_push($dupcona, $spdt['email']);
    		
    	else if($spdt['status']=="statuse")
    		array_push($dupconr, $spdt['email']);
    }	  
     
    $statusa=implode(',',$dupconp); 
    $statusb=implode(',',$dupconb); 
    $statusc=implode(',',$dupcone); 
    $statusd=implode(',',$dupcona); 
    $statuse=implode(',',$dupconr);
    PHP:
    "example" table contains following fields :
    email (varchar2)
    name (varchar2)
    status (varchar2)
    id (int)
    date (date)

    Problem :
    $statusa, $statusb, $statusc, $statusd, $statuse contains nothing.

    Thanks in advance. :)
     
    Mr. Pimp, Dec 20, 2009 IP
  2. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What do you get if you add a catch-all if inside the loop:

    else
    echo $spdt['status'];
     
    jedi.knight, Dec 20, 2009 IP
  3. Mr. Pimp

    Mr. Pimp Active Member

    Messages:
    142
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    it gives :
    statusd
    statusa
    statusc
    statuse
    statusd
    statusd
    statuse
    statusa
    Code (markup):
     
    Mr. Pimp, Dec 20, 2009 IP
  4. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Really strange!!!

    Try to convert each "==" to a strncmp? For example:

    
    if (strncmp($spdt['status'], "statusa", 7) == 0)
    
    Code (markup):
    Is there a newline at the end of each value of $spdt['status']? Try to do a "echo strlen($spdt['status'])" to see if it prints 7 or 8.

    Good luck!
     
    jedi.knight, Dec 20, 2009 IP
  5. yoes_san

    yoes_san Peon

    Messages:
    443
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Or try using '===' instead of '=='
     
    yoes_san, Dec 22, 2009 IP
  6. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #6
    Are you getting anything if you do
    echo count($statusa);
     
    dreteh, Dec 24, 2009 IP