Php 将mysqli_num_行与while循环和onclick事件一起使用

Php 将mysqli_num_行与while循环和onclick事件一起使用,php,jquery,mysql-num-rows,Php,Jquery,Mysql Num Rows,我想回显行数(假设行数=3)。如果用户单击该行数(我从while循环中传递1个参数),则数据会发出警报 但问题是 若我在while循环中回显numrows,则所有行(相关的3行数据)都会在onclick事件中发出警报,但numrows会像333一样显示3次 如果我在while循环之外进行回显,那么num行只显示一次,但只向函数传递一个结果 我还使用了count(col),但这样只检索一个结果 一次显示行数但将$uid(在while循环中)的所有结果传递给onclick函数的任何解决方案?.Plz

我想回显行数(假设行数=3)。如果用户单击该行数(我从while循环中传递1个参数),则数据会发出警报 但问题是

  • 若我在while循环中回显numrows,则所有行(相关的3行数据)都会在onclick事件中发出警报,但numrows会像333一样显示3次
  • 如果我在while循环之外进行回显,那么num行只显示一次,但只向函数传递一个结果
  • 我还使用了count(col),但这样只检索一个结果

    一次显示行数但将$uid(在while循环中)的所有结果传递给onclick函数的任何解决方案?.Plz帮助

      $sql=mysqli_query($this->db->connection,"SELECT * from user_data where  scid='$scid'");
                $num=mysqli_num_rows($sql);
    
                while($row=mysqli_fetch_array($sql)){
                    $uid=$row['uid'];
    
    
    
                    ?>
    
    
                <span onclick=o4_sameby_scid(<?php echo $uid;  ?>)><?php echo  $num  ?></span>
    
    
    
                <script type="text/javascript">
    
                    function o4_sameby_scid(o4_id) {
                        alert(o4_id);
                    }
    
    
                </script>
    
    
    
                <?php
                }
    
    $sql=mysqli\u查询($this->db->connection,“SELECT*from user\u data,其中scid='$scid');
    $num=mysqli\u num\u行($sql);
    while($row=mysqli\u fetch\u数组($sql)){
    $uid=$row['uid'];
    ?>
    
    我认为您的问题在于您在
    while
    循环中嵌套了错误的代码部分。这种方法怎么样

    <?php
    $sql=mysqli_query($this->db->connection,"SELECT * from user_data where  scid='$scid'");
    $num=mysqli_num_rows($sql);
    
    $allvalues = array();
    
    //  Do all looping before any echoing
    while($row=mysqli_fetch_array($sql)){
        // add this row's value to an array of all values
        $allvalues[] = $uid=$row['uid'];
    }
    
    // implode this array
    $valuesascsv = implode(', ', $allvalues);
    
    
    //  This is echo'd outside of the loop, because we only need to see it one time
    echo '<span onclick=o4_sameby_scid("'. $valuesascsv .'")>'. $num .' results found! </span>';
    ?>
    
    <script type="text/javascript">
        function o4_sameby_scid(o4_id) {
            alert(o4_id);
        }
    </script>
    

    @itachi循环中$uid的结果问题很模糊。请解释
    一次显示num行但将所有结果传递给onclick函数的任何解决方案?
    此部分。可能会有一个例子。@itachi.plz检查问题。我以什么格式更新了上述行?如
    1,2,3,…。
    或其他格式,谢谢你。Exa确切地说,我希望得到相同的结果,但u plz是否可以从警报(在javascript标记之前)中取出while循环以使其更简单?
    <span onclick=o4_sameby_scid("uid#1, uid#2, uid#3")>3 results found!</span>
    
    <script type="text/javascript">
        function o4_sameby_scid(o4_id) {
            alert(o4_id);
        }
    </script>