2017-06-22 91 views
-3

我从Page1中选择了多个ID并发送到正在工作的Page2,现在我必须显示所有ID到功能名称fake_user_archive进行删除。我在函数中获得空值。如何将数组中的数值从一个函数传递给另一个函数?

例如: 我有ID号1,5,20,50。我从Page1中选择并将该ID发送到page2。我的代码将检查电子邮件状态,如果状态为1,它将调用下一个函数,称为fake_user_archive,并且电子邮件将被删除。但我没有得到任何价值的功能。 page1.php

这不是我的整个代码。仅供参考。

<?php 
while ($stmt->fetch()) { 
    echo"<input type='checkbox' name='check_list[]' value='".$id."'>"; 
}?> 

使page2.php

switch($_GET['function']) { 
    case 'checking':checking($conn);break; 
    default : redirect('index.php'); 
    } 
    function checking($conn) 
    { 
    // loop over checked checkboxes 
    foreach($_POST['check_list'] as $checkbox) { 

     //echo $checkbox;//displaying all id 
     $sql_all="SELECT * FROM `request` WHERE Id='".$checkbox."'"; 
     $result_chk=$conn->query($sql_all); 
      if (isset($result_chk->num_rows) > 0) { 
       while($row = $result_chk->fetch_assoc()) { 
        $r_email_verify=$row['email_verification']; 

       } 
      } 

      if ($r_email_verify == 1) { 
       fake_user_archive($conn);//calling the function but getting empty 
      } 
else{ 
other_function(); 
} 

    }//foreach 

    } 

    function fake_user_archive($conn) 
    { 
     // how do i get here all my id which is selected from page1.php 
     //deactive id here 
    } 
+0

你为什么要将$ conn传递给函数,这似乎是你的数据库连接?你说你想通过一个ID - 那么是什么阻止你这样做? – CBroe

+0

传递'$ checkbox'而不是'$ conn'。 'fake_user_archive($ checkbox);' –

+0

将它作为第二个参数传递,像这样:fake_user_archive($ conn,$ checkbox); – JYoThI

回答

1

1:你可以通过Nparameter到功能通过像这样

fake_user_archive($conn,$checkbox); 

第二:功能应该是

function fake_user_archive($conn,$checkbox) 
{ 
    var_dump($checkbox); 
} 
+0

感谢您的回复,但它不工作,里面的功能我试图显示回声$复选框,但没有任何显示 –

+0

里面的函数,你可以把var_dump($ checkbox);出口;并看到输出@NarendraVerma – JYoThI

+0

我做了什么我选择了id号码4858,4859,4860,我得到了像数组(3){[0] =>字符串(4)“4858”[1] =>字符串(4) “4859”[2] => string(4)“4860”} array(3){[0] => string(4)“4858”[1] => string(4)“4859”[2] =>字符串(4)“4860”} –

相关问题