0

I have this code:

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    if($i++%2==0){
       $color="#FFFFFF";
    }else{
       $color="#CCCCCC";
    }

    ?>

    <tr bgcolor='<?php echo $color; ?>' onmouseover="this.style.background='#ABFB04';" onmouseout="this.style.background='<?php echo $color; ?>';">
    <?php

echo "<td class=tablelist>";

echo $row["ICAO"] . '</td><td class=tablelist>';

echo $row["Name"] . '</td><td class=tablelist>';

echo $row["WeightEmpty"] . '</td><td class=tablelist>';

echo $row["WeightFull"] . '</td><td class=tablelist>';

echo $row["CargoFull"] . '</td><td class=tablelist>';

echo $row["Range"] . '</td><td class=tablelist>';

echo $row["Price"] . '</td><td class=tablelist>';

echo $row["FirstClassSeats"] . '</td><td class=tablelist>';

echo $row["BusinessClassSeats"] . '</td><td class=tablelist>';

echo $row["EconomyClassSeats"]. '</td><td class=tablelist>';

echo "<img class='editaircraft' src='./images/info.png'></td></tr>"; 

?>
<script>
    $(function() {
        $( "#editaircraftdialog" ).dialog({
            autoOpen: false,
            width: 425
        });

        $( ".editaircraft" ).click(function() {
            $( "#editaircraftdialog" ).dialog( "open" );
            return false;
        });
    }); 
</script>

<div id="editaircraftdialog" title="Edit Aircraft">
    <?php require_once('./new_aircraft.php'); ?> 
</div>

<?php
}

echo "</table>";
$pagination->render();
?>

The problem is here:

<div id="editaircraftdialog" title="Edit Aircraft">
        <?php require_once('./new_aircraft.php'); ?> 
    </div>

If I use the require once in a while it not works. But if the require is out a while it works fun. If i change the require_once and I put text, It works fun.

The problem is what I see the content of the require_once out a dialog like this: http://i50.tinypic.com/k1aslk.png

The while stops when it arrive to the <div>.

new_aircraft.php

<script>
    $(function() {
        $("#insertaircraft")
            .button()
            .click(function(event) {
        });
    });
</script>

<form action="new_aircraft_process.php" method="post" enctype="application/x-www-form-urlencoded">
    <table>

    <tr><td class="forms">ICAO:</td><td><input maxlength="4" type="text" name="icao" size="30"/></td></tr>

    <tr><td class="forms">Name:</td><td><input type="text" name="name" size="30"/></td></tr>

    <tr><td class="forms">Weight Empty:</td><td><input type="text" name="weightempty" size="30"/></td></tr>

    <tr><td class="forms">Weight Full:</td><td><input type="text" name="weightfull" size="30"/></td></tr>

    <tr><td class="forms">Cargo Full:</td><td><input type="text" name="cargofull" size="30"/></td></tr>

    <tr><td class="forms">Cruise Speed:</td><td><input type="text" name="cruisespeed" size="30"/></td></tr>

    <tr><td class="forms">Range:</td><td><input type="text" name="range" size="30"/></td></tr>

    <tr><td class="forms">Price:</td><td><input type="text" name="price" size="30"/></td></tr>

    <tr><td class="forms">Number Classes:</td><td><select name="numberclasses" id="numberclasses">
        <option value="0">Select Number of Classes</option>
        <?php
        echo '<option value="1">One Classes (Economy)</option>';
        echo '<option value="2">Two Classes (Business & Economy)</option>';
        echo '<option value="3">Three Classes (First, Business & Economy)</option>';
        ?>
    </select></td></tr>



    <tr><td class="forms">First Class Seats:</td><td><input disabled="disabled" type="text" id="firstclassseats" name="firstclassseats" size="30"/></td></tr>

    <tr><td class="forms">Business Class Seats:</td><td><input disabled="disabled" type="text" id="businessclassseats" name="businessclassseats" size="30"/></td></tr>

    <tr><td class="forms">Economy Class Seats:</td><td><input disabled="disabled" type="text" id="economyclassseats" name="economyclassseats" size="30"/></td></tr>

<script type="text/javascript">

$("#numberclasses").change(function() {
value = $(this).val();

str = parseInt(value);

switch(str)
  {
    case 0:
    $(document).ready(function() {
        $("#firstclassseats").attr("disabled","disabled");
        $("#businessclassseats").attr("disabled","disabled");
        $("#economyclassseats").attr("disabled","disabled");
});
    break;

    case 1:
    $(document).ready(function() {
        $("#economyclassseats").removeAttr('disabled');
        $("#firstclassseats").attr("disabled","disabled");
        $("#businessclassseats").attr("disabled","disabled");
});
    break;

     case 2:
    $(document).ready(function() {
        $("#businessclassseats").removeAttr('disabled');
        $("#economyclassseats").removeAttr('disabled');
        $("#firstclassseats").attr("disabled","disabled");
});
    break;

    case 3:
    $(document).ready(function() {
        $("#firstclassseats").removeAttr('disabled');
        $("#businessclassseats").removeAttr('disabled');
        $("#economyclassseats").removeAttr('disabled');
});
    break;

  }
});

</script>

    <tr><td></td><td><input id="insertaircraft" type="submit" value="Insert Aircraft"/></td></tr>
    </table>
</form>
  • And again :D `mysql` extension is outdated and not maintained for a looong time time. With PHP5.5 it will be finally marked as deprecated. Use `PDO_MYSQL`, or `MySQLi` instead. http://php.net/en/mysql-connect – KingCrunch Jan 07 '13 at 20:08
  • require_ONCE. iF it's inside a loop, it means it's called multiple times.. – Damien Pirsy Jan 07 '13 at 20:08
  • 1
    this also could help http://stackoverflow.com/q/2418473/1055987 – JFK Jan 07 '13 at 20:09
  • The require only or include dont works I have the same error! – user1949821 Jan 07 '13 at 20:12
  • I can't see the error you're getting. What error are you talking about? – Damien Pirsy Jan 07 '13 at 20:14
  • The error is what the include is out of JQuery Dialog. And the new_aircarft.php is perfect because if yo do the include out of while all works fun! – user1949821 Jan 07 '13 at 20:20
  • 5 comments and 2 answers and you still unable to describe the problem. -1. – Salman A Jan 07 '13 at 20:25
  • Ok, I have a JQuery Dialog and it is on a PHP While. The while stops when it arrive at the
    and the content of the require is out a JQuery Dialog. If I change the include for a text or I put the include out the while all works fun. I put a link to picture in the question: http://i50.tinypic.com/k1aslk.png
    – user1949821 Jan 07 '13 at 20:29
  • Can you post the content of './new_aircraft.php'. Since you claim that the script halts on the while when it reaches the
    and you claim that `include` behaves the same as `require`, then it stands to reason that the problem MUST lie within this './new_aircraft.php' file
    – PassKit Jan 07 '13 at 20:39
  • No problem. You can see it in the question post! – user1949821 Jan 07 '13 at 20:45
  • There's so much wrong here and you stil have not been able to explain presicely what the problem is. Your markup has duplicate ID tags (meaning your Javascript events will not trigger as expected), you are repeating the Javascript on each iteration of the loop and your script tag is in an invalidly located between two table rows, plus you are insist that the loop halts when using `include` - which from what you have posted above seems impossible. – PassKit Jan 07 '13 at 21:04

2 Answers2

3

Notice the _once part. Once you've included that file, it will not be included again until the script exits and a new instance is fired up. This is by design. if you want the file each time, then use require() instead.

Marc B
  • 356,200
  • 43
  • 426
  • 500
2

change require_once to require or to include. Because of the 'once' your script will only include the file on the first iteration.

The difference between require and include is that require will break your code with an error if PHP cannot find the file.

include will trigger a warning but allow your script to continue.

PassKit
  • 12,231
  • 5
  • 57
  • 75
  • It, dont works. I have the same error! – user1949821 Jan 07 '13 at 20:11
  • Try using `include` instead of `require` - if your code is breaking, it is most likely because require cannot find the './new_aircraft.php' file. Otherwise, there could be an error in the './new_aircraft.php' file. – PassKit Jan 07 '13 at 20:13
  • Nothing!! It dont works!! – user1949821 Jan 07 '13 at 20:22
  • It dont works!! doesn't help us much - can you be more specific about what you expect to see vs. what you are seeing, plus if possible post the content of your PHP server logs? – PassKit Jan 07 '13 at 20:24
  • You can see a picture here: http://i50.tinypic.com/k1aslk.png – user1949821 Jan 07 '13 at 20:32
  • The picture tells us nothing about what you expect vs. what you are getting. I can't see anything wrong in your pic, because you have not told us what you expect to see. – PassKit Jan 07 '13 at 20:35
  • I put new_aircraft.php in the question post. What else I can put? – user1949821 Jan 07 '13 at 20:46