Need Quick Help with PHP

Discussion in 'Programming' started by mcmuney, Feb 18, 2012.

  1. #1
    
        $query = "SELECT smg_from,COUNT(smg_to),smg_body FROM sc_messages WHERE smg_from=$social_mem_id GROUP BY smg_body DESC LIMIT 10";
        $result = mysql_query($query) or die(mysql_error());
        while($row = mysql_fetch_array($result)){
    	echo "There are ". $row['COUNT(smg_to)'] ." ". $row['smg_body'] ." items.";
    	echo "<br />";
    	}
    
    Code (markup):
    RESULT:
    There are 8 hi items.
    There are 5 hey items.
    There are 1 hay items.

    How can I write this if statement: if array result contains a $row['COUNT(smg_to)'] > 5???

    Any help would be greatly appreciated.

    Thanks.
     
    mcmuney, Feb 18, 2012 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Hi,
    is that you're asking for:
    $query = "SELECT smg_from,
    COUNT(smg_to),
    smg_body 
    FROM sc_messages 
    WHERE smg_from={$social_mem_id} 
    GROUP BY smg_from,smg_body DESC 
    HAVING(COUNT(smg_to)>5) LIMIT 10";
    
    PHP:
     
    koko5, Feb 18, 2012 IP
  3. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    echo "There are ". $row['COUNT(smg_to)'] ." ". $row['smg_body'] ." items.";
    PHP:
    it will like

     if($row['COUNT(smg_to)']  > 5) { echo "There are ". $row['COUNT(smg_to)'] ." ". $row['smg_body'] ." items."; } 
    PHP:
     
    zappak, Feb 18, 2012 IP
  4. nikipatel

    nikipatel Member

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    
    $query = "SELECT smg_from,COUNT(smg_to) AS cnt, smg_body FROM sc_messages WHERE smg_from=$social_mem_id GROUP BY smg_body DESC LIMIT 10";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
          echo "There are ". $row[cnt] ." ". $row['smg_body'] ." items.";
          echo "<br />";
    }
    
    PHP:
     
    nikipatel, Feb 18, 2012 IP
  5. nikipatel

    nikipatel Member

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    
    $query = "SELECT smg_from,COUNT(smg_to) AS cnt, smg_body FROM sc_messages WHERE smg_from=$social_mem_id GROUP BY smg_body DESC LIMIT 10";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
          echo "There are ". $row[cnt] ." ". $row['smg_body'] ." items.";
          echo "<br />";
    }
    
    PHP:
     
    nikipatel, Feb 18, 2012 IP
  6. mcmuney

    mcmuney Well-Known Member

    Messages:
    834
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    As Seller:
    100% - 0
    As Buyer:
    100% - 3
    #6
    Thank for all the help!
     
    mcmuney, Feb 19, 2012 IP