duanrebo3559 2013-07-18 15:13
浏览 39
已采纳

从带有按钮数组的文本框数组中获取值

it's the 2nd time i post here. Again i'm not too proficient in logic nor PHP, so please bear with my messy codes :)

I have an array of textboxes with value and there are array of buttons next to it. i've managed to display the value of the text box with the corresponding button into a dialog box (thanks to Mr.Barmer from here)

Then i intend to save the specific value from the textbox that i have captured into the database, here i have no clue what i should do. I try to "echo" the value of the textbox by insert it into

($link=((document.getElementById('link$i').value)))

but i got no result.

My question is: what should i add to my codes to retrieve the value from the textbox, when i clicked the corresponding button and save it to database, or simply capture the value and store it in

(ex:$link=$_POST['link'])

then post it using echo $link?

here's the piece of my PHP codes i'm talking about:

$data = mysql_query("SELECT * from tempimg"); 
while($hasil = mysql_fetch_array($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'>

        <label class=text_label> $hasil[imgLink]</label>
        <div class=edit></div>
        <input type=text align=center value=$hasil[imgLink] 
                name=link[{$hasil['idFoto']}] id=link$i />
        <div class=clear></div> 

        <td align=center>

        <button type=submit =
            onClick=\"return confirm('you clicked button $i 
                with ID: $hasil[idFoto] '+'value: '
                +(document.getElementById('link$i').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 SS of the page that i'm working now http://imgur.com/FtKAs8K

just need to get the "70" and the "test.com" value and "echo" it, the rest of database query i'll try to work out myself. So i humbly request help from the people here, please help me. Thank you for your attention

  • 写回答

1条回答 默认 最新

  • douang1243 2013-07-18 16:41
    关注

    First of all, you'll need to change your PHP code (above) to look like this:

    <script>
    $(function() {
        $(document).on('click','.saveButton',function() {
            var imageNumber = $(this).closest('tr').data('imgNum');
            var imageLink = $(this).closest('tr').data('imgLink');
            $.get('process_img.php',{n:imgNumber,l:imgLink});
        });
    });
    </script>    
    <?php
    $data = mysql_query("SELECT * from tempimg"); 
    while($hasil = mysql_fetch_array($data)){     
        $i++;
    ?>
    <tr data-imgNum="<?=$i;?>" data-imgLink="<?=$hasil['imgLink'];?>">
        <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'>
            <label class="text_label"><?=$hasil['imgLink'];?></label>
            <div class="edit"></div>
            <input type="text" align="center" value="<?=$hasil['imgLink'];?>" name="link[{<?=$hasil['idFoto'];?>}" id="link<?=$i;?>" />
            <div class="clear"></div> 
        </td>
        <td align="center">
            <input type="button" class="saveButton">
                <img src="images/sav.png" alt="search-btn" id="img" />
            </input>
        </td>
        <td align="center"><img src="images/del.png" /></td>
    <?php
    }
    ?>
    

    Then you'll need to write a new PHP script named process_img.php:

    <?php
    $n = $_REQUEST['n']; // this is the NUMBER (70)
    $i = $_REQUEST['i']; // this is the LINK (test.com)
    //  save this info to the database
    ?>
    

    This gives you a terrific head start. Look for tutorials online.......

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

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)