在php中while循环的按钮

时间:2013-12-24 14:08:27

标签: javascript php html

我想点击显示详细信息时显示url detect的详细信息,但我找不到解决此问题的方法。

enter image description here

我可以向所有网址显示详细信息,因为它在while循环但我想要一行???请帮我 这段代码:     

<div class="content">

    <a href="logout.php" class="a-btn">
        <span class="a-btn-text">&nbspHI&nbsp<?php echo $login_session; ?></span>
        <span class="a-btn-slide-text">Sign Out</span>
        <span class="a-btn-icon-right"><span></span></span>
    </a>
</div>
<div style="height:49px">

</div>


<div class="form-wrapper-01">

    <input type="text" id="search" name="search" placeholder="Enter your URL" " onClick="f()"
    value="<?php echo $search; ?>">
    <input type="submit" name="s" value="Search" id="submit" onClick="ff()">


</div>
<span style="margin:22px;color:green;font-size:20px"> <?php echo $ss; ?></span>

<?php


if (isset($_POST['s'])) {

    if (!empty($_POST["search"])) {
        echo '<div class="example" id="cc" style=" border:2px solid;padding:8px;font-size:19px;
margin:12px;width:960px;height:580px;box-shadow: 10px 10px 5px #888888;overflow-x:auto;overflow-y:auto">';

        $sq   = "SELECT * FROM $feed_url WHERE URL LIKE '%$search%'";
        $sear = mysqli_query($bd, $sq);
        //mysqli_query($bd,"UPDATE feed_urls SET publisher_logo_url = 'http://a.abcnews.com/assets/images/navigation/abc-logo.png' WHERE URL LIKE '%$search%'");    
        while ($result = mysqli_fetch_array($sear)) {

            echo $result['URL'];
            $c = "availability";
            echo " ";
            echo '<input type="submit" name="ss" value="Show Details" id="s2" />';
            echo '<span id="availability">';
            echo '</span>';
            echo "<br>";
            echo "<br>";
            echo "<hr>";


        }

        $anymatches = mysqli_num_rows($sear);
        if ($anymatches == 0) {
            echo "Sorry, but we can not find an entry to match your query...";
        }
        //echo '<a href="tt2.php" style="text-decoration:none;"><span style="color: red;margin-left:7cm;">Top</span></a>';
        echo '</div>';
    } else {
        $searche   = "<br>";
        $searcherr = "* Insert URL in Field";

    }

}

?>
<span style="color: red;"><?php echo "$searcherr" ?></span>

</form>

1 个答案:

答案 0 :(得分:2)

当我说得对,每个“显示详细信息”按钮都具有相同的ID 所以我们开始改变他们的ID 当你开始使用id =“s2”时,我也将从2开始计算:

var i =2;
    while ($result = mysqli_fetch_array($sear)) {

        echo $result['URL'];
        $c = "availability";
        echo " ";
        echo '<input type="submit" name="ss" value="Show Details" id="s'+i+'" onClick="show('i')"/>'; 
        echo '<span id="availability'+i+'">';
        echo '</span>';
        echo "<br>";
        echo "<br>";
        echo "<hr>";
        i++;

    }

所以每个Button和Span都获得相同的变量ID,因为我认为你想在该Span中插入一些东西:

    function show(id){
    // document.getElementById('"availability"+id') = the span of the button clicked, show xy
    }

不知道我是否在正确的道路上,但是maby这对你有用