douxie1894 2013-07-17 22: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-17 22: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部