Query

Discussion in 'PHP' started by baris22, Jul 21, 2010.

  1. #1
    hello,

    i can get the result on phpmyadmin by doing:


    
    SELECT topic, COUNT( * ) AS usercount FROM `file` GROUP BY topic HAVING usercount >1
    
    PHP:


    how can i addapt this to my current query?


    
    $query = "SELECT COUNT(*) as num FROM file ";    
    $total_pages = mysql_fetch_array(mysql_query($query));    
    $total_pages = $total_pages[num];    
    
    /* my codes continues.................*/  
    
     /* Get data. */    
    $sql = "SELECT * FROM file ORDER BY topic DESC LIMIT $start, $limit";    
    $result = mysql_query($sql);
    
    
    PHP:

    thanks alot.
     
    baris22, Jul 21, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    I'm not sure about your desired result-set but you can try the following
    
    $sql = "SELECT * FROM `file` NATURAL JOIN 
    (SELECT topic, COUNT( * ) AS usercount FROM `file` GROUP BY topic HAVING usercount >1) A
    ORDER BY A.topic DESC LIMIT {$start}, {$limit}";
    
    PHP:
    Regards :)
     
    koko5, Jul 22, 2010 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    thanks for replie.


    here is my code:


    
    $query = "SELECT COUNT(*) as num FROM file ";    
    $total_pages = mysql_fetch_array(mysql_query($query));    
    $total_pages = $total_pages[num];    
    
    /* my codes continues.................*/   
    
    
    $sql = "SELECT * FROM file ORDER BY topic DESC LIMIT $start, $limit";    /* Get data. */    
    $result = mysql_query($sql);
    
    
    PHP:


    I want to show duplicated rows according to topic field. How can i do it on my code?

    Thaks alot.
     
    baris22, Jul 25, 2010 IP
  4. manzar

    manzar Peon

    Messages:
    111
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i think your problems is shut out after using this code if not reply me right error

    $query = "SELECT COUNT(*) as num FROM file ";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];
     
    manzar, Jul 27, 2010 IP