Home > Backend Development > PHP Tutorial > PHP_SQL_'date' processing for database reading

PHP_SQL_'date' processing for database reading

WBOY
Release: 2016-07-29 08:59:13
Original
970 people have browsed it

<code><span><span><?php </span><span>require</span>(<span>"header.php"</span>);

    <span>$sql</span> = <span>"SELECT entries.*, catetories.cat FROM entries, catetories
        WHERE entries.cat_id = catetories.id
        ORDER BY dateposted DESC
        LIMIT 1;"</span>;
        <span>//数据库知识,$sql构建查询语句(排序后,最新日期的数组为第一个,limit 1指只取一个)</span><span>$result</span> = mysql_query(<span>$sql</span>);
    <span>//把查询语句$sql通过mysql_query()语句发送到数据库,并把结果(表)存在$result中</span><span>$row</span> = mysql_fetch_assoc(<span>$result</span>);
    <span>//把$result中的表通过mysql_fetch_assoc()方法一个个存在$row数组中</span><span>echo</span><span>"<h2><a href="viewentry.php?id=%22</span>.<span>%24row</span>%5B<span>" id>].<span>"'>"</span>.<span>$row</span>[<span>'subject'</span>].<span>"</span></a></h2>
<br>"</span>;
    <span>echo</span><span>"<i>In <a href="viewcat.php?id=%22</span>.<span>%24row</span>%5B<span>" cat_id>].<span>"'>"</span>.<span>$row</span>[<span>'cat'</span>].<span>"</span></a> - Posted on "</i></span>.<span>$row</span>[<span>'dateposted'</span>].<span>""</span>;
    <span>//date("D jS F Y g.iA",strtotime($row['dateposted']))</span><span>echo</span><span>"<p>"</p></span>;
    <span>echo</span> nl2br(<span>$row</span>[<span>'body'</span>]);
    <span>//这个函数将$row['body']的内容里面的空行转换成html的<br>,最后一行关闭段落标签</span><span>echo</span><span>""</span>;
    <span>//以上涉及html代码格式,以php读取数据的方式构建html</span><span>//viewentry.php 和 viewcat.php是另外的php网页,与本次测试无关</span><span>require</span>(<span>"footer.php"</span>);
    <span>?></span></span></span></code>
Copy after login

Use $row['dateposted'] directly, what is displayed is:
PHP_SQL_date processing for database reading

Source code processed by functions date() and strtotime():

<code><span>echo</span><span>"<i>In <a href="viewcat.php?id=%22</span>.<span>%24row</span>%5B<span>" cat_id>].<span>"'>"</span>.<span>$row</span>[<span>'cat'</span>].<span>"</span></a> - Posted on "</i></span>.date(<span>"D jS F Y g.iA"</span>,strtotime(<span>$row</span>[<span>'dateposted'</span>])).<span>""</span>;
</code>
Copy after login

Effect screenshot:
PHP_SQL_date processing for database reading

').addClass ('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the "date" processing of PHP_SQL_database reading, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template