Heim  >  Artikel  >  Backend-Entwicklung  >  PHP-Lernen-1

PHP-Lernen-1

WBOY
WBOYOriginal
2016-07-29 09:10:45910Durchsuche

Ein kleines Einführungsexperiment

<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>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

Das Obige hat PHP Learning-1 vorgestellt, einschließlich verschiedener Aspekte. Ich hoffe, es wird für Freunde hilfreich sein, die sich für PHP-Tutorials interessieren.

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:Späte Bindung in PHPNächster Artikel:Späte Bindung in PHP