使用PHP将数据从html表添加到表单中

First of all, i have a complicated table with values resulted from queries.The table is displayed as wanted http://i58.tinypic.com/dux5i.jpg . What i'm trying to do.. is use the variable $posibilitate into a second query after the button is pressed so i can echo it into the div with id="belet". The part after if($_POST['butonel']) isn't working as intended, it only displays the last value from the second query . This is how my table posibilitate looks like: http://i57.tinypic.com/t4y71f.jpg. Below you have my full script of the page.

 <?php
 $idcompetitie=$_GET['idcompetitie'];
 $sql="SELECT  idpariu, titlu, data_sfarsit from pariu WHERE idcompetitie=".$idcompetitie;
 $resursa=mysql_query($sql);
 while($row=mysql_fetch_array($resursa))
{
?>
 <tbody id="belet">
 <tr>
 <td class="meciuri" width="210px"  align="left" color="#666666">
 <?php echo $row['titlu']?> </td>
 <td class="data" width="120px" align="center" >
 <?php echo $row['data_sfarsit']?>
 </td>

 <td class="cote" align="right">
 <?php
 if($idcompetitie)
 {
 $sql1="select cota, idposibilitate from posibilitate where idpariu=".$row['idpariu'];
 $resursa1=mysql_query($sql1) or die(mysql_error());

while($row1=mysql_fetch_array($resursa1))
        {
  $cota=$row1['cota'];
  $posibilitate=$row1['idposibilitate'];
 $_SESSION['poss']=$row1['idposibilitate']; 
 echo "<td class='odds' id='$posibilitate'  ><form action='' method='post'> <input type='submit' name='butonel' value='$cota'/></form></td>" ;

if($_POST['butonel'])     
{
$sql2="SELECT titlu, data_sfarsit, idposibilitate, numeposibilitate, cota FROM posibilitate , pariu  WHERE posibilitate.idpariu=pariu.idpariu AND posibilitate.idposibilitate='$posibilitate'";
$resursa2=mysql_query($sql2) or die(mysql_error());
while ($row2=mysql_fetch_array($resursa2))
{
$posibilitati= $row2['cota'];
$idpos=$row2['idposibilitate'];
$datapos=$row2['data_sfarsit'];
$numepos=$row2['numeposibilitate'];
$titlul=$row2['titlu'];
$cotapos=$row2['cota'];

$belet = "<form action='' method='post'>
<input type='text' name='posibilitate' value='$idpos'/>
<input type='text' name='titlu' value='$titlul' /><br/>
<input type='text' name='cota' value='$cotapos'/>
<input type='submit' name='button' value='x' /><br/>
    </form>";
}
}
                }
} 
 ?>
</td>
</tbody>
</tr>
<?php
}
?>
</table>
</td>
</div>
<div id="belet">
<?php
 echo $belet;
 ?>

I've been trying to use arrays or a different php file but i can't seem to get that variable $posibilitate working for the next query.

Thanks for reading, any suggestions would be really helpfull.

After 1st query, your $posibilitate only save the last $row1 value. So when you clicked your "button1" => you only have the last $row1 value. That's all i can help. I don't understand what you want to do with this code.

I don't understand what you want to do too. But i see some mistakes in your code. At first good advice - don't use mysql_query. It is not good way to make queries. Use PDO or mysqli instead. Second, in first query yuo have

$row1=mysql_fetch_array($resursa1)

but then

  $row['titlu'];
  $row['data_sfarsit'];
  $row['idpariu'];

And, finally, if you want to get each value of $posibilitate you must second 'while' put into first 'while'. And do all the things inside the second cycle.