µ±Ç°Î»ÖãºLinux½Ì³Ì - Php - ±äÁ¿µÄ±äÁ¿,PHPºÍÄã

±äÁ¿µÄ±äÁ¿,PHPºÍÄã

ÔÚÎÒ×î½ü×öµÄÒ»¸öÏîÄ¿ÖУ¬ÎÒ·¢ÏÖÁËÒ»¸öеĸÅÄ¹ØÓÚÔÚPHPÖÐʹÓñäÁ¿µÄ±äÁ¿¡£ÔÚÎҵijÌÐòÖУ¬ÎÒÐèÒªÔÚÒ»¸öÒ³Ãæͬʱ¸üжà¸ö¼Ç¼£¬ÔÚÎÒ¾­¹ýÏ൱³¤Ê±¼äµÄÍ´¿à˼Ë÷Ö®ºó£¬ÄÔº£ÖÐżȻµØÉÁÏÖ³öÁ˱äÁ¿µÄ±äÁ¿£¨variable variable£©ÕâÒ»¸ÅÄËùÓеÄÀ§»ó¾Íһɨ¶ø¹âÁË¡£

½éÉÜ

ʲô½Ð×÷±äÁ¿µÄ±äÁ¿£¿¸ù¾ÝPHPÊֲᣬ±äÁ¿µÄ±äÁ¿ÊÇָȡµÃÒ»¸ö±äÁ¿µÄÖµ²¢°ÑËü×÷ΪÁíÒ»¸ö±äÁ¿µÄ±äÁ¿Ãû¡£Õâ±íÊöÏÔµÃÏ൱µÄÖ±½Ó£¬ÈÝÒ׺ÍÄÇЩÔÚÒ»¸ö¾ä×ÓÖÐʹÓá°±äÁ¿¡±Õâ¸ö´ÊŪ»ìÏý¡£¸øÒ»¸ö¼òµ¥µÄÀý×Ó£¬Ä㶨ÒåÒ»¸ö±äÁ¿ --- x µÈÓÚ this ---¡¡È»ºó¶¨ÒåÒ»¸ö±äÁ¿µÄ±äÁ¿£¬Òâζ×ÅÄã°Ñ x µÄÖµ×÷ΪбäÁ¿µÄÃû£¬ÔÚÕâ¸öÀý×ÓÖУ¬Õâ¸öбäÁ¿µÄÖµÊÇ is cake¡£ÓÃPHPÀ´±íʾÈçÏ£º

<?php

$x = "this";
$$x = "is cake";

?>

Õâ¸ö·ûºÅ$$ÊÇÔÚPHPÖжԱäÁ¿µÄ±äÁ¿µÄ±íʾ·½·¨¡£ÏÖÔÚÎÒÃÇ¿ÉÒÔÓÃÁ½ÖÖ²»Í¬µÄ·½Ê½À´ÒýÓÃÕâÁ½¸ö±äÁ¿ $x ºÍ $$x¡¡ÁË¡£

<?php

echo "$x ${$x}";

?>

<?php

echo "$x $this";

?>

ÉÏÃæÁ½¶Î³ÌÐò¶¼½«Êä³ö this is cake¡£×¢Ò⣬ÔÚechoÓï¾äÖÐ$$x±»Ð´³É${$x}£¬ÕâÊÇÈÃPHPÖªµÀÄãÒªÊä³öµÄÊDZäÁ¿µÄ±äÁ¿¶ø²»ÊÇÒ»¸ö$×Ö·ûÓë$x±äÁ¿¡£

ÄãÊDz»ÊÇÈÔºÜÃÔ»ó£¿Å¶£¬Ò²Ðí°É£¬ÄãÏëҪһЩ¸üÉîÈë¸üÓÐÓõÄÀý×Ó£¿ÏÂÒ»½Ú£¬ÎÒ½«ÏòÄãչʾÔõÑùÓñäÁ¿µÄ±äÁ¿ÔÚÒ»¸öÒ³Ãæ±à¼­¶àÌõ¼Ç¼µÄ¡£


Àý×Ó

¼ÙÉèÄãÒÑÓÐÒ»¸öMySQLÊý¾Ý¿â£¬±£´æÁ˶ÔһЩ¸ÐÐËȤµÄÕ¾µãµÄÁ´½Ó£¬¿âÖÐÓÐÒ»¸ö±ísubmissions£¬×Ö¶ÎÈçÏ£º

SubmissionID
PostedBy
Link
Description
Approved

ÏÖÔÚÄãÏëÏÔʾÔÚ±íÖÐËùÓеÄÒÑ´´½¨µ«Ã»Óб»ÈϿɵÄÁ´½Ó£¬Õâ¸ö±à¼­µÄÒ³ÃæÓ¦¿ÉÒÔ¸üÕýһЩÊäÈëʱµÄ´íÎ󣬲¢ÓÃÊʵ±µÄµ¥Ñ¡°´Å¥À´ÎªÃ¿Ò»¸ö¼Ç¼ÉèÖÃÊÇ·ñÔÊÐí(Approved)£¬È»ºóÒ»´Î°Ñ¸üкóµÄ¼Ç¼¶¼Ìá½»µ½±íÖС£

Ê×ÏÈ£¬µ±Äã´ÓÊý¾Ý¿â³öÌáÈ¡ËùÓеļǼ²¢ÏÔʾ³öÀ´Ê±£¬Äã±ØÐëΪÿһ¸ö¼Ç¼ÉèÖÃÒ»¸öΨһµÄÃû×Ö£¬Õ⽫ÈÃÎÒÃÇÔÚÌύʱ¿ÉÒÔÑ­»·µØ±ç±ð³ö¸÷¸ö¼Ç¼µÄÖµ¡£´úÂëÈçÏ£º

<?php

//³õʼ»¯±äÁ¿µÄ¼ÇÊýÆ÷

$index = 0;
$index_count = 0;

echo "<form method=post action=$PHP_SELF>n";
echo "<table>n";
echo "<tr><td><b>Posted By</b></td><td><b>Link</b></td>".
"<td><b>Description</b></td><td><b>Approved</b></td></tr>n";


/*********
¼Ù¶¨ÎÒÃÇÒÑ´ÓÊý¾Ý¿âÖмìË÷³ö¼Ç¼µ½Ò»¸öÊý×éÖС¡
$myrow = mysql_fetch_array().
ÏÂÃæµÄ do...while Ñ­»·¸ù¾ÝÃû×ÖΪÿһ¸ö$xstr±äÁ¿·ÖÅäÁËÒ»¸öÖµ²¢ÇÒÁ¬½ÓÁË$index µÄÖµµ½½á⣬ÒÔ0Ϊ¿ªÊ¼¡£
ÕâÑù£¬Õâ¸öÑ­»·µÄµÚÒ»´Îʱ£¬$SubmissionIDStr µÄÖµ¾ÍÊÇ¡¡SubmissionID0 £¬µÚ¶þ´Î¾ÍÊÇ SubmissionID1 £¬ÒÔ´ËÀàÍÆ¡£
***********/

do {

$SubmissionIDStr = SubmissionID.$index;
$PostedByStr = PostedBy.$index;
$LinkStr = Link.$index;
$DescriptionStr = Description.$index;
$ApprovedStr = Aprroved.$index;


//ÕâÒ»¶Î½«ÔÚÆÁÄ»ÉÏÏÔʾֵ£¬ÒÔÿÐÐÒ»Ìõ¼Ç¼¡£

printf("<tr><td><input type=hidden name=%s value=%s><input type=text name=%s value=%s></td>
<td><input type=text name=%s value=%s></td><td><input type=text name=%s value=%s></td>
<td><input type=radio name=%s value=-1>Yes<input type=radio name=%s value=0 checked>No</td></tr>n",
$SubmissionIDStr, $myrow["SubmissionID"], $PostedByStr, $myrow["PostedBy"], $LinkStr, $myrow["Link"],
$DescriptionStr, $myrow["Description"], $ApprovedStr, $ApprovedStr);


//ÿ¸öÑ­»·¼ÇÊýÆ÷¼Ó1

$index++;
$index_count++;

} while ($myrow = mysql_fetch_array($result));

// ´´½¨Ò»¸öË÷Òý¼ÇÊýÆ÷index_countÀ´¸ú×ÙËùÓеļǼÊý

echo "<INPUT TYPE=hidden NAME=counter VALUE=$index_count>n";

echo "<INPUT TYPE=submit></form>n";

?>

Ìá½»ÒÔºó£¬ÎÒÃÇÀûÓÃ$index_count±äÁ¿ÔÙÒ»´ÎÑ­»·±éÀúÒ³ÃæÉÏËùÓеıäÁ¿£¬È»ºó£¬·ÖÅäÕâЩ±äÁ¿¸øÁíһЩ±äÁ¿£¬Õâ¾ÍÓõ½Á˱äÁ¿µÄ±äÁ¿¡£

<?php

//Õâ¸öÑ­»·±éÀúËùÓÐÒ³ÃæÉÏÏÔʾµÄ¼Ç¼

for ($index = 0; $index <= $counter; $index++) {


/*****
Õⲿ·ÖÓÃÎÒÃÇÔÚÇ°Ãæ´´½¨µÄÃû×ÖÉèÖÃÁËеıäÁ¿
´Ó0¿ªÊ¼£¬Ö±µ½$index_count
*****/

$varSubmissionID = 'SubmissionID'.$index;
$varPostedBy = 'PostedBy'.$index;
$varLink = 'Link'.$index;
$varDescription = 'Description'.$index;
$varApproved = 'Approved'.$index;


/******
ÕâÊDZäÁ¿µÄ±äÁ¿²¿·Ö£¬°Ñÿ¸öÖµ·ÖÅä¸øÿ¸öбäÁ¿µÄÃû¡£
ÀýÈ磬µÚÒ»´ÎÑ­»·Ê±£¬·ÖÅä¸ø¼Ç¼ SubmissionID0¡¡ÊÇ´ÓÇ°ÃæµÃÀ´µÄÖµ£¬ÎÒÃÇÓñäÁ¿µÄ±äÁ¿À´ÁËÈ¡µ½Ëü¡£
*******/

$SubmissionIDvalue = $$varSubmissionID;
$PostedByvalue = $$varPostedBy;
$Linkvalue = $$varLink;
$Descriptionvalue = $$varDescription;
$Approvedvalue = $$varApproved;


//¸üÐÂÊý¾Ý¿â

$sql = "UPDATE submissions SET PostedBy='$PostedByvalue',Link='$Linkvalue',".
"Description='$Descriptionvalue' WHERE SubmissionID=$SubmissionIDvalue'";
$result = mysql_query($sql);


//Èç¹û±¾¼Ç¼±»ÉèÖÃΪapproved£¬¸üÐÂÏàÓ¦µÄ×ֶΡ¡Approved¡£

if ($Approvedvalue == '-1') {
$sql = "UPDATE submissions SET Approved='-1' WHERE SubmissionID=$SubmissionIDvalue";
$result = mysql_query($sql);
}

}

?>

ÎÒÏ£ÍûÕâÓÐÖúÓÚÄãÃ÷°×Õâ¸ö±äÁ¿µÄ±äÁ¿µÄ»ù±¾Ó÷¨£¬²¢ÇÒÔÚÄ㽫À´µÄ¹¤×÷ÖÐʹÓÃËüÃÇÌṩһЩ˼·¡£±äÁ¿µÄ±äÁ¿ÕâÒ»¸ÅÄ×î³õÒ²ÊÇÈÃÎÒÍ·Í´µÄ¶«Î÷£¬µ«ÊÇÒ»µ©ÄãÖªµÀÁËËüÃǹ¤×÷µÄ»ù±¾Ô­Àíʱ£¬ËüÃǾͱä³ÉÁËÒ»¿éÃÀζµÄ±ÈÈø±ý¡£