表单只从表中的第一行获取数据

时间:2015-11-07 12:54:23

标签: php html

我在执行以下操作时遇到了一些问题,我将尝试解释清楚我的问题是什么。我有一个包含大量行的HTML表格......我使用带有按钮的HTML表单,当您单击它时,它会将信息发送到另一个PHP脚本,并且它工作正常,除了它只是获取第一行的信息,无论你点击它还在哪里发送第一行的数据,这是我到目前为止所尝试的:

<?php
$pilotid = Auth::$userinfo->pilotid;
$last_location = RealScheduleLiteData::get_pilot_location($pilotid, 1);
$last_name = OperationsData::getAirportInfo($last_location->arricao);
$biddata = SchedulesData::GetBid($sched_data->bidid);
?>
<h3><b>Job Offers</b></h3>

<ul>

</ul>

<table width="100%" border="0" cellspacing="0" class="table table-striped m0 p0 mt0" style="table-layout:fixed;">
    <tr class="table-header">
        <td colspan="6">Available jobs from <?php echo $last_location->arricao.' ( '.$last_name->name.')' ;?></td>
    </tr>

<?php
if(!$allroutes)
{
?>
    <tr><td align="center">No flights from <?php echo $last_location->arricao.' ( '.$last_name->name.')' ;?>!</td></tr>

<?php
}
else
{
?>
<script src="http://skyvector.com/linkchart.js"></script>


    <tr class="table-header">
    <th width="10%" align="center">Airline</th>
    <th width="10%" align="center">Flight ID</th>
    <th width="10%" align="center">Departure</th>
    <th width="10%" align="center">Arrival</th>
    <th width="10%" align="center">Aircraft</th>
    <th width="30%" colspan=1" align="left">Options</th>
</tr>

<?php
foreach($allroutes as $route)
{
    if(Config::Get('DISABLE_SCHED_ON_BID') == true && $route->bidid != 0)
    {
        continue;
    }
    if(Config::Get('RESTRICT_AIRCRAFT_RANKS') === true && Auth::LoggedIn())
    {
        if($route->aircraftlevel > Auth::$userinfo->ranklevel)
        {
            continue;
        }
    }
?>

<tr class="table-data">
        <td width="20%" align="left" valign="middle"><?php echo '<img src="'.fileurl('/airlines/'.$route->code.'.png').'" alt="'.$airline->name.'" />'; ?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->code . $route->flightnum?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->depicao ;?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->arricao ;?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->aircraft ;?></td>
        <td width="20%" align="left" valign="middle"><input type="button" value="Job Description" onclick="$('#details_dialog_<?php echo $route->flightnum;?>').toggle()">
        <form id="sbapiform">

        <input type="button" onclick="simbriefsubmit('http://www.virtualaviationgroup.com/index.php/SimBrief');" style="font-size:14px" value="Generate Flight Plan">
<table>
    <tr>
       <?php $planedata=(OperationsData::getAircraftByReg($route->registration)) ;?>
        <td><input type="hidden" name="type" size="5" type="text" placeholder="ZZZZ"  value="<?php echo $planedata->icao ;?>"></td>
    <tr>

    <tr>
         <td><input type="hidden" name="orig" size="5" type="text" placeholder="ZZZZ" maxlength="4" value="<?php echo $route->depicao ; ?>"></td>
    <tr>

    <tr>
       <td><input type="hidden" name="dest" size="5" type="text" placeholder="ZZZZ" maxlength="4" value="<?php echo $route->arricao ; ?>"></td>
    <tr>

    <tr>
       <td><input type="hidden" name="route" placeholder="Enter your route here"></td>
    </tr>

    <tr>
        <td colspan=2></td>
    </tr>

    <tr>
       <td><input type="hidden" name="units" size="5" type="text" placeholder="ZZZZ" maxlength="4" value="KGS"></td>
    </tr>

</table>


<input type="hidden" name="airline" value="<?php echo $route->code?>"> 

<input type="hidden" name="fltnum" value="<?php echo $route->flightnum?>"> 

<?php $today = date("dMy");?>

<input type="hidden" name="date" value="<?php echo $today?>"> 

<?php $deptimes = explode(":", $route->deptime); ?>

<input type="hidden" name="deph" value="<?php echo $deptimes[0]?>">
<input type="hidden" name="depm" value="<?php echo $deptimes[1]?>">    

<?php $arrtimes = explode(":", $route->arrtime); ?>

<input type="hidden" name="steh" value="<?php echo $arrtimes[0]?>">
<input type="hidden" name="stem" value="<?php echo $arrtimes[1]?>">



<input type="hidden" name="reg" value="<?php echo $route->registration?>">    


 <input type="hidden" name="navlog" value="1"> 
<input type="hidden" name="selcal" value="GR-FS">    

<input type="hidden" name="planformat" value="lido">





</form>


       <?php 
        if($biddata->pilotid == $pilotid && $route->bidid != 0)
        {
        ?>
        <input type="button" value="You´re Hired!"
        <?php
        }
        else
        {
        ?>
        <a id="<?php echo $route->id; ?>" class="addbid" href="<?php echo url('/schedules/addbid');?>"><input type="button" value="Accept Job"</a>
        <?php                    
        }
        ?>

    </td>
</tr>

        <td colspan="6">

        <table cellspacing="10" cellpadding="10" border="0" class="table table-striped m0 p0 mt0" id="details_dialog_<?php echo $route->flightnum;?>" style="display:none" width="100%">

            <tr>
            <th align="left" colspan="4">Flight Brefing</th>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspDeaprture:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php
            $name = OperationsData::getAirportInfo($route->depicao);
            echo "{$name->name}"?></b></td>
            <td align="left">&nbsp&nbspArrival:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php 
            $name = OperationsData::getAirportInfo($route->arricao);
            echo "{$name->name}"?></b></td>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspAircraft</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php 
            $plane = OperationsData::getAircraftByName($route->aircraft);
            echo $plane->fullname ; ?></b></td>
            <td align="left">&nbsp&nbspDistance:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->distance . Config::Get('UNITS') ;?></b></td>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspDep Time:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->deptime?> GMT</font></b></td>
            <td align="left">&nbsp&nbspArr Time:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->arrtime?> GMT</font></b></td>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspAltitude:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->flightlevel; ?> ft</b></td>
            <td align="left">&nbsp&nbspDuration:</td>
            <td colspan="0" align="left" ><b>&nbsp
            <?php 

            $dist = $route->distance;
            $speed = 440;
            $app = $speed / 60 ;
            $flttime = round($dist / $app,0)+ 20;
            $hours = intval($flttime / 60);
            $minutes = (($flttime / 60) - $hours) * 60;
            if($hours > "9" AND $minutes > "9")
            {
            echo $hours.':'.$minutes ;
            }
            else
            {
            echo '0'.$hours.':0'.$minutes ;
            }
            ?> Hrs</b></font></td>
            </tr>
            <tr>

            <tr>
            <td align="left">&nbsp&nbspFlight Type:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php
            if($route->flighttype == "P")
            {
            echo'Passenger' ;
            }
            if($route->flighttype == "C")
            {
            echo'Cargo' ;
            }
            if($route->flighttype == "H")
            {
            echo'Charter' ;
            }
            ?></b></td>
            <td align="left">&nbsp&nbspFlown</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->timesflown ;?></b></td>
            </tr>
            </tr>
            <tr>
            <th align="center"colspan="4">Flight Map</th>
            </tr>
            <tr>
            <td width="100%" colspan="4">
            <?php
            $string = "";
                        $string = $string.$route->depicao.'+-+'.$route->arricao.',+';
                        ?>
<img width="100%" src="http://www.gcmap.com/map?P=<?php echo $string ?>&amp;MS=wls2&MR;MR=240&amp;MX=680x200&amp;PM=pemr:diamond7:red%2b%22%25I%22:red&amp;PC=%230000ff" />


</div>

</tr>
</td>
         </table>   

        </td>
</tr>


<?php
}
}
?>
</table>
<br />
<hr>
<br />

<center><a href="<?php echo url('/FrontSchedules') ;?>"><input type="submit" name="submit" value="Back to Flight Booking System" ></a></center>

对不起,如果这个问题不够好,或者已经问到了,我找不到任何类似的东西。请不要对我粗鲁

亲切的问候!!

- 编辑 -

我有这些表(我没有在代码中显示,因为它与这些没有任何关系)

Table

每当你点击“生成飞行计划”按钮时,它会调用函数发送我在代码中显示的所有变量......问题是它只适用于那里显示的第一个航班。因为如果你点击第2,第3,第4,第5 ......无论它发送第1个数据的数据。

1 个答案:

答案 0 :(得分:0)

在包含表格的文件中,将for循环更改为:

<?php
foreach($allroutes as $route)
{
    $formid = isset($formid)? $formid+1 : 1;

进一步在您的按钮页面上,将其更改为:

<input type="button" onclick="simbriefsubmit('http://www.virtualaviationgroup.com/index.php/SimBrief', <?= $formid ?>);" style="font-size:14px" value="Generate Flight Plan">

...这里我们为simbriefsubmit()电话添加了第二个参数。

将表单标记更改为:

<form id="sbapiform<?= $formid?>">

...现在所有表格都有唯一的ID。

现在我们需要在JS中添加/更改几行。第742行首先:

function simbriefsubmit(outputpage, formid)
{
    if (!formid) 
        var formid = '';

...然后在同一个函数中,在第768行:

do_simbriefsubmit(outputpage, formid);

在第773行:

function do_simbriefsubmit(outputpage, formid)
{
    if (!formid)
        var formid = '';

...第799行和第804行:

setTimeout(function(){do_simbriefsubmit(outputpage, formid);},500);

......最后在第813行:

var apiform = document.getElementById(sbform + formid);

我们所做的是为每个表单创建唯一ID,并将ID传递给javascript函数,以便他们可以获取正确的表单。

函数中的if语句确保不会破坏对该函数的任何现有调用。