douxie1894 2013-07-18 06:02
浏览 29
已采纳

使用特定的数组按钮从文本框数组中检索特定值

I am new here and i trying to make some PHP page working but failed miserably. I am not very good with logic nor PHP, so please bear with my stupid question and my messy codes :)

I have array of textboxes with value and there are array of buttons next to it. what i want is each button capture specific value what i typed into the corresponding textbox

here's the piece of my code

<?php
  $data = mysql_query("SELECT * from tempimg"); 
  while($hasil = mysql_fetch_assoc($data)){   
    $i++;
  echo "<tr>
        <td align=center><input type= checkbox name=check[] value=$hasil[idFoto]</td>
        <td align=center><img src=$hasil[thumbPath]></td>
        <td align=center>$hasil[imgName]</td>
        <td align=center>$hasil[thumbPath]</td>
        <td align=center>$hasil[Path]</td>
        <td align=center>

        <input type=text align=center value=$hasil[imgLink] name=link[{$hasil['idFoto']}] id=link />

        <td align=center>
        <button type=submit onClick=\"return confirm('you clicked button  with ID: $hasil[idFoto] '+'value: '+(document.getElementById('link').value))\">
        <img src=images/sav.png alt=search-btn id=img />
        </button>
        </td>
        <td align=center><img src=images/del.png></img></td>";    
  }

      ?>

and here's the link of image for the PHP page I'm talking about

enter image description here

enter image description here

so I humbly request of help from people here, please help me.

EDIT: thanks to Mr. Barmar i manage to pop out the value of the text box inside the dialog box with the corresponding button,

here a new question, how to save the value from the text box that i got from clicking the corresponding button into the database?

or more simple, how to capture the value from the text box by using the button next to it and then post it on the screen using "echo"

  • 写回答

1条回答 默认 最新

  • doudai8083 2013-07-18 06:16
    关注

    You need to give all the id=XXX attributes unique values, by including $i in the ID. Then your onclick code can get the value of the input from the same row.

    <?php
      $data = mysql_query("SELECT * from tempimg"); 
      while($hasil = mysql_fetch_assoc($data)){   
        $i++;
      echo "<tr>
            <td align='center'><input type='checkbox' name='check[]' value='$hasil[idFoto]'</td>
            <td align='center'><img src='$hasil[thumbPath]'></td>
            <td align='center'>$hasil[imgName]</td>
            <td align='center'>$hasil[thumbPath]</td>
            <td align='center'>$hasil[Path]</td>
            <td align='center'>
    
            <input type='text' align='center' value='$hasil[imgLink]' name='link[{$hasil['idFoto']}]' id='link$i' />
    
            <td align='center'>
            <button type='submit' onclick='return confirm(\"you clicked button  with ID: $hasil[idFoto] \"+\"value: \"+(document.getElementById(\"link$i\").value))'>
            <img src='images/sav.png' alt='search-btn' id='img$i' />
            </button>
            </td>
            <td align='center'><img src='images/del.png' /></td>";    
      }
    
          ?>
    

    You should also put quotes around all attribute values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?