Heim > php教程 > php手册 > php独特的语法

php独特的语法

WBOY
Freigeben: 2016-06-06 19:46:47
Original
1331 Leute haben es durchsucht

今天写一个程序的时候遇到一个很有意思的问题,这个和php独特的语法有关,首先我们看一下代码是怎么写的。 ? php $db = mysql_connect ('localhost','root','Ctrip07185419') or die ('can not connect to databas' ); mysql_select_db ('moviesite', $db )

今天写一个程序的时候遇到一个很有意思的问题,这个和php独特的语法有关,首先我们看一下代码是怎么写的。

<span>php 
</span><span>$db</span> = <span>mysql_connect</span>('localhost','root','Ctrip07185419') or <span>die</span>('can not connect to databas'<span>);
</span><span>mysql_select_db</span>('moviesite',<span>$db</span>) or <span>die</span>(<span>mysql_error</span>(<span>$db</span><span>));

</span><span>if</span>(!<span>isset</span>(<span>$_GET</span>['do']) || <span>$_GET</span>['do'] != 1<span>)
{
    </span><span>switch</span>(<span>$_GET</span>['type'<span>])
    {
        </span><span>case</span> 'movie':
        <span>echo</span> 'Are you sure you want to delete this movie?<br>'<span>;
        </span><span>break</span><span>;
        </span><span>case</span> 'people':
        <span>echo</span> 'Are you sure you want to delete this people?<br>'<span>;
        </span><span>default</span>:
        <span>break</span><span>;
    }
    </span><span>echo</span> '<a href="'.<span>%24_SERVER</span>%5B'REQUEST_URI'%5D.'&do=1">Yes</a> or <a href="admin.php">no</a>'<span>;
}
</span><span>else</span><span>
{
    </span><span>switch</span>(<span>$_GET</span>['type'<span>])
    {
        </span><span>case</span> 'people':
            <span>$query</span> = ' update people set movie_leadactor = 0 where movie_leadactor = '.<span>$_GET</span>['id'<span>];
            </span><span>$result</span> = <span>mysql_query</span>(<span>$query</span> , <span>$db</span>) or <span>die</span>(<span>mysql_error</span>(<span>$db</span><span>));
            </span><span>$query</span> = ' delete from people where people_id='.<span>$_GET</span>['id'<span>];
            </span><span>$result</span> = <span>mysql_query</span>(<span>$query</span> , <span>$db</span>) or <span>die</span>(<span>mysql_error</span>(<span>$db</span><span>));
                    
</span>?>
<p style="text-align:'center'">Your person has been deleted</p>
<a href="admin.php"><span>Return</span> to Index</a>
<span>php 
        </span><span>break</span><span>;
        </span><span>case</span> 'movie':
            <span>$query</span> = 'delete from movie where movie_id='.<span>$_GET</span>['id'<span>];
            </span><span>$result</span> = <span>mysql_query</span>(<span>$query</span> , <span>$db</span>) or <span>die</span> (<span>mysql_error</span>(<span>$db</span><span>));
</span>?>
<p style="text-align:'center'">Your movie has been deleted</p>
<a href="admin.php"><span>Return</span> to Index</a>
<span>php
        </span><span>break</span><span>;
        </span><span>default</span>:
        <span>break</span><span>;
    }
}
</span>?>
Nach dem Login kopieren

注意这里的switc语句,在删除movie或people之后我们要输出成功信息并返回列表页面,一般情况下我们习惯把break语句紧跟在switch下面的主体部分,于是开始的时候我写成这样了

<span>else</span><span>
{
    </span><span>switch</span>(<span>$_GET</span>['type'<span>])
    {
        </span><span>case</span> 'people':
            <span>$query</span> = ' update people set movie_leadactor = 0 where movie_leadactor = '.<span>$_GET</span>['id'<span>];
            </span><span>$result</span> = <span>mysql_query</span>(<span>$query</span> , <span>$db</span>) or <span>die</span>(<span>mysql_error</span>(<span>$db</span><span>));
            </span><span>$query</span> = ' delete from people where people_id='.<span>$_GET</span>['id'<span>];
            </span><span>$result</span> = <span>mysql_query</span>(<span>$query</span> , <span>$db</span>) or <span>die</span>(<span>mysql_error</span>(<span>$db</span><span>));
        </span><span>break</span><span>;            
                    
</span>?>
<p style="text-align:'center'">Your person has been deleted</p>
<a href="admin.php"><span>Return</span> to Index</a>
Nach dem Login kopieren

把break放在了case下面的语句下面,这样会导致不能输出删除成功信息,

Your pers
Return to Index

这两句是可以当成case语句的一部分的,如果把它放在外面将永远也不会执行,所以要break要放在下一个case的开头,将上面两行html片段放在case语句中,这样就可以正常显示删除成功的信息了。

php面条语句的特性在这里表现的淋漓尽致。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
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
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage