• April 22, 2023
    how different? :
    
    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') { // form submitted
    $x = $_POST['x'];
    $t="12345"}
    else { // form not submitted 
    $t= "";}
    echo $t;
    ?>
    and 
    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {// form submitted
    $x = $_POST['x'];
    $t="12345"
    echo $t;}
    else {// form not submitted
    $t= "";}
    ?>

    The two code snippets you provided will produce the same result because they both define $t to be “12345” when the form is submitted, and then output the value of $t using echo.

    The only difference between the two snippets is the order of the statements inside the conditional block. In the first snippet, the value of $t is assigned before the conditional block is closed, and then it is output using echo. In the second snippet, the value of $t is assigned and output in the same statement, inside the conditional block.

    Both approaches are valid, but the first snippet may be more readable because it separates the variable assignment from the output statement. Additionally, if you need to perform multiple operations on $t before outputting it, it may be more convenient to define it first and then operate on it later.

    In summary, both snippets will produce the same output, but the first snippet may be easier to read and modify in the future.

    ทดสอบความแตกต่างโดยใส่ echo “111”; echo “222”; echo “333”; ในแต่ละส่วน

    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') { // form submitted
    $x = $_POST['x'];
    $t="12345"}
    echo "111";
    else { // form not submitted 
    $t= "";
    echo "222";}
    echo $t;
    echo "333";
    ?>

    ผลที่ได้
    รันไฟล์จะแสดง 222 , 333
    กด submit จะแสดง 111 , 333

    สรุป
    ถ้าต้องการให้ แสดงเมื่อกด submit ต้องใส่ที่ตำแหน่ง 111
    สำหรับ 333 จะแสดงทุกกรณี
    สำหรับ 222 จะแสดงกรณีไม่กด submit เท่านั้น

    นำตำแหน่ง 222 ไปใช้ แก้ปัญหา บทความก่อนหน้านี้ได้
    https://vir9.com/shows-a-message-while-pressing/
    เอาข้อความไปไว้ล่างปุ่ม ที่ต้องกดเพื่อคำนวณ
    ข้อความจะบอกว่า ต้องใส่ข้อมูลอะไรบ้าง
    เมื่อกดแล้ว ตอนแสดงผลข้อความนี้จะไม่โชว์อีก



เวอไนน์ไอคอร์ส

ประหยัดเวลากว่า 100 เท่า!






เวอไนน์เว็บไซต์⚡️
สร้างเว็บไซต์ ดูแลเว็บไซต์

Categories