开发者

Need a script that will stream the newest MySQL field entrys

I want a PHP script to stream all new entries to a MySQL field. So lets say there are 10 of the newest displaying on a page, in time order because the field has a datetime. If anyone can help it would be gre开发者_运维问答at.


The SQL you'll need will be along the lines of the following

SELECT * FROM table ORDER BY datetimeField DESC LIMIT 10

Then you just iterate over the result of your query in your PHP.


<?php

    // connect to the database at 127.0.0.1 (localhost) 
    // with username mysql_username and password mysql_password
    $link = mysql_connect('127.0.0.1', 'mysql_username', 'mysql_password');

    // fire off query
    $result = mysql_query("SELECT fieldname FROM tablename ORDER BY datefield DESC LIMIT 10", $link);


    // loop through results, displaying field.
    while ($row = mysql_fetch_assoc($result)) {
            echo $row['fieldname'];
    }

    // close the connection to the database
    mysql_close($link);

?> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜