Home > Backend Development > PHP Tutorial > PHP learning-1

PHP learning-1

WBOY
Release: 2016-07-29 09:10:45
Original
946 people have browsed it

A little introductory experiment

<code><html>
<title>My First Hello World</title>
<body>
    <span><?php</span><span>// ?和php之间不能有空格</span><span>if</span>(!<span>empty</span>(<span>$_POST</span>[<span>'name'</span>]))
        {
            <span>echo</span><span>"Hello, {$_POST['name']}, Welcome to Our Web"</span>;
        }
    <span>?></span>    <form action=<span>"<?php $PHP_SELF; ?>" method=<span>"post"</span>>
        Enter Your Name:<input type=<span>"text"</span> name=<span>"name"</span>/>
        <input type=<span>"submit"</span>/>
    </form>

    <span><?php</span><span>$mysql_host</span> = <span>"8.8.8.8"</span>;
    <span>$mysql_user</span> = <span>"guess"</span>;
    <span>$mysql_pwd</span>  = <span>"guess"</span>;
    <span>$connect</span> = mysql_connect(<span>$mysql_host</span>,<span>$mysql_user</span>,<span>$mysql_pwd</span>) <span>or</span><span>die</span>(<span>"connect failed"</span> . mysql_error());
    mysql_select_db(<span>"md_guess"</span>, <span>$connect</span>);
    <span>$sql</span> = <span>"select * from t_user_1 limit ${_POST['name']};"</span>;
    <span>$result</span> = mysql_query(<span>$sql</span>, <span>$connect</span>);

    <span>if</span>(<span>$result</span>)
    {
        <span>// 获取列表名</span><span>$title</span> = <span>array</span>();
        <span>for</span> (<span>$i</span>=<span>0</span>; <span>$i</span><mysql_num_fields(<span>$result</span>); <span>$i</span>++)
        {
            <span>$title</span>[<span>$i</span>] = mysql_field_name(<span>$result</span>, <span>$i</span>);
        }

        <span>$data</span> = <span>array</span>();
        <span>$num</span> = <span>0</span>;
        <span>// 获取数据</span><span>while</span> (<span>$row</span>=mysql_fetch_row(<span>$result</span>))
        {
            <span>$item</span> = <span>array</span>();
            <span>for</span> (<span>$i</span>=<span>0</span>; <span>$i</span><mysql_num_fields(<span>$result</span>); <span>$i</span>++ )
            {
                <span>$item</span>[<span>$i</span>] = <span>$row</span>[<span>$i</span>];
            }
            <span>$data</span>[<span>$num</span>] = <span>$item</span>;
            <span>$num</span> += <span>1</span>;
        }

        <span>// 显示数据</span><span>echo</span><span>'<table border="1" cellpadding="1" cellspacing="2">'</span>;

        <span>for</span>(<span>$i</span>=<span>0</span>; <span>$i</span><count(<span>$title</span>); <span>$i</span>++)
        {
            <span>echo</span><span>"<tr>";

            <span>echo</span><span>"<td>"</span>;
            <span>echo</span><span>$title</span>[<span>$i</span>];
            <span>echo</span><span>"</td>"</span>;

            <span>for</span>(<span>$j</span>=<span>0</span>; <span>$j</span><count(<span>$data</span>); <span>$j</span>++)
            {
                <span>echo</span><span>"<td>"</span>;
                <span>echo</span><span>$data</span>[<span>$j</span>][<span>$i</span>];
                <span>echo</span><span>"</td>"</span>;
            }

            <span>echo</span><span>"</tr>"</span>;
            <span>//echo "<br>";</span>
        }

        <span>echo</span><span>"</table>"</span>;
    }
    <span>else</span>
    {
        <span>echo</span><span>"Query Failed"</span>;
    }

    <span>if</span>(<span>$result</span>)
    {
        mysql_freeresult(<span>$result</span>);
    }
    mysql_close(<span>$connect</span>);

    <span>?></span>
</body>
</html></code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced PHP learning-1, including various 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