long executation

Discussion in 'PHP' started by promotingspace.net, Jul 16, 2007.

  1. #1
    Hi
    what is ther problem of this code:
    <?php
    include'global.php';
    $result=mysql_query("SELECT * FROM articles ORDER BY id LIMIT 20");
    $row = mysql_fetch_array($result);
    while($row){
    
    echo $title=$row['title'],$name=$row['name'];
    }
    ?>
    PHP:
    It brings a long result after a long time ( so long that IE cannot browse it and I have to use firefox)
    in addition, the result is not what I need. I need the title of 20 last post articles
     
    promotingspace.net, Jul 16, 2007 IP
  2. Tim_Myth

    Tim_Myth Peon

    Messages:
    741
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Part of the problem is the select statement. I don't know the names of your DB fields (use phpmyadimn to find out), but it should be something like this:

    $result=mysql_query("SELECT `title` FROM `articles` ORDER BY `id` LIMIT 20");

    That is assuming your id is the key. If id is not an autogenerated number, then you'll want to order by submission date.
     
    Tim_Myth, Jul 16, 2007 IP
  3. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    solved!
    while(mysql_fetch_array($result))
     
    promotingspace.net, Jul 16, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Actually, the best way is:
    
    while ($row = mysql_fetch_array($result))
    
    PHP:
     
    nico_swd, Jul 16, 2007 IP