Maison  >  Article  >  développement back-end  >  PHP学习-1

PHP学习-1

WBOY
WBOYoriginal
2016-07-29 09:10:45910parcourir

入门小实验

<code>
<title>My First Hello World</title>

    <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; ?>"</form></span> method=<span>"post"</span>>
        Enter Your Name:<input type="<span">"text" name=<span>"name"</span>/>
        <input type="<span">"submit"/>
    

    <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>$result</mysql_num_fields></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>$result); <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>for</span>(<span>$i</span>=<span>0</span>; <span>$i</span><count>$title); <span>$i</span>++)
        {
            <span>echo</span><span>"<tr>";

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

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

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

        <span>echo</span><span>"</span></count>
</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>

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

以上就介绍了PHP学习-1,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:PHP中的后期绑定Article suivant:使用phpdbg来调试php程序