1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simplification of a SQL query

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

  1. #1
    hi everyone,
    SEMrush
    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
    SEMrush
  2. mwasif

    mwasif Active Member

    Messages:
    818
    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