Simplification of a SQL query

Discussion in 'PHP' started by Kyriakos, Nov 26, 2008.

  1. #1
    hi everyone,

    i have a SQL query and i want to simplificate him. php code
    $result=mysql_query("SELECT * FROM products WHERE cid='$cid' AND status=1 ORDER BY $sort");
    
    $rows=mysql_num_rows($result);
    
    $result=mysql_query("SELECT * FROM products WHERE cid='$cid' AND status=1 ORDER BY $sort LIMIT " . ($pg-1)*$limit . ",$limit");
    
    $NumberOfPages=ceil($rows/$limit);
    PHP:
    can anybody help me? i want to use 1 SQL query. not 2 like above.

    thanks in advance
     
    Kyriakos, Nov 26, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Use SQL_CALC_FOUND_ROWS and FOUND_ROWS(), see MySQL Manual.
     
    mwasif, Nov 26, 2008 IP