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.

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大